Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.Data/System.Data.Common/RecordCache.cs')
-rw-r--r--mcs/class/System.Data/System.Data.Common/RecordCache.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/mcs/class/System.Data/System.Data.Common/RecordCache.cs b/mcs/class/System.Data/System.Data.Common/RecordCache.cs
new file mode 100644
index 00000000000..0cb454887c4
--- /dev/null
+++ b/mcs/class/System.Data/System.Data.Common/RecordCache.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections;
+
+namespace System.Data.Common
+{
+ internal class RecordCache
+ {
+ #region Fields
+
+ const int MIN_CACHE_SIZE = 128;
+
+ Stack _records = new Stack(16);
+ int _nextFreeIndex = 0;
+ int _currentCapacity = 0;
+ DataTable _table;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ internal RecordCache(DataTable table)
+ {
+ _table = table;
+ }
+
+ #endregion //Constructors
+
+ #region Properties
+
+ internal int CurrentCapacity
+ {
+ get {
+ return _currentCapacity;
+ }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ internal int NewRecord()
+ {
+ if (_records.Count > 0) {
+ return (int)_records.Pop();
+ }
+ else {
+ DataColumnCollection cols = _table.Columns;
+ if (_nextFreeIndex >= _currentCapacity) {
+ _currentCapacity *= 2;
+ if ( _currentCapacity < MIN_CACHE_SIZE ) {
+ _currentCapacity = MIN_CACHE_SIZE;
+ }
+ foreach(DataColumn col in cols) {
+ col.DataContainer.Capacity = _currentCapacity;
+ }
+ }
+ return _nextFreeIndex++;
+ }
+ }
+
+ internal void DisposeRecord(int index)
+ {
+ if ( index < 0 ) {
+ throw new ArgumentException();
+ }
+ _records.Push(index);
+ }
+
+ #endregion // Methods
+
+ }
+}