Author: gbayon
Date: Sat Apr  1 02:02:59 2006
New Revision: 390635

URL: http://svn.apache.org/viewcvs?rev=390635&view=rev
Log:
- Refactoring ParameterPropertyColection to remove boxing

Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterPropertyCollection.cs

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs?rev=390635&r1=390634&r2=390635&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterMap.cs
 Sat Apr  1 02:02:59 2006
@@ -2,7 +2,7 @@
 #region Apache Notice
 /*****************************************************************************
  * $Header: $
- * $Revision$
+ * $Revision: 390227 $
  * $Date$
  * 
  * iBATIS.NET Data Mapper
@@ -262,15 +262,11 @@
                {
                        string[] propertyNameArray = new 
string[_propertiesMap.Count];
 
-                       IEnumerator myEnumerator = 
_propertiesList.GetEnumerator();
-                       int index =0;
-                       while ( myEnumerator.MoveNext() )
+                       for (int index=0;index<_propertiesList.Count;index++)
                        {
-                               propertyNameArray[index] = 
((ParameterProperty)myEnumerator.Current).PropertyName;
-                               index++;
+                               propertyNameArray[index] = 
_propertiesList[index].PropertyName;
                        }
-
-                       return (propertyNameArray); 
+                       return propertyNameArray; 
                }
 
 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterPropertyCollection.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterPropertyCollection.cs?rev=390635&r1=390634&r2=390635&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterPropertyCollection.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ParameterMapping/ParameterPropertyCollection.cs
 Sat Apr  1 02:02:59 2006
@@ -23,111 +23,230 @@
  
********************************************************************************/
 #endregion
 
-using System.Collections;
+using System;
 
 namespace IBatisNet.DataMapper.Configuration.ParameterMapping
 {
        /// <summary>
        /// A ParameterProperty Collection.
        /// </summary>
-       public class ParameterPropertyCollection: CollectionBase 
+       public class ParameterPropertyCollection
        {
+               private const int _defaultCapacity = 8;
+               private const int _capacityMultiplier = 2;
+               private int _count = 0;
+               private ParameterProperty[] _innerList = null;
+
+
+               /// <summary>
+               /// ead-only property describing how many elements are in the 
Collection.
+               /// </summary>
+               public int Count 
+               {
+                       get { return _count; }
+               }
+
+
                /// <summary>
-               /// Constructeur
+               /// Constructs a ArrayList. The list is initially empty and has 
a capacity
+               /// of zero. Upon adding the first element to the list the 
capacity is
+               /// increased to 8, and then increased in multiples of two as 
required.
                /// </summary>
-               public ParameterPropertyCollection() {}
+               public ParameterPropertyCollection() 
+               {
+                       _innerList = new ParameterProperty[_defaultCapacity];
+                       _count = 0;
+               }
 
+               /// <summary>
+               ///  Constructs a ParameterPropertyCollection with a given 
initial capacity. 
+               ///  The list is initially empty, but will have room for the 
given number of elements
+               ///  before any reallocations are required.
+               /// </summary>
+               /// <param name="capacity">The initial capacity of the 
list</param>
+               public ParameterPropertyCollection(int capacity) 
+               {
+                       if (capacity < 0)
+                       {
+                               throw new 
ArgumentOutOfRangeException("Capacity", "The size of the list must be >0.");
+                       }
+                       _innerList = new ParameterProperty[capacity];
+               }
 
                /// <summary>
-               /// Acces element in collection by index
+               /// Length of the collection
+               /// </summary>
+               public int Length
+               {
+                       get{ return _innerList.Length; }
+               }
+
+ 
+               /// <summary>
+               /// Sets or Gets the ParameterProperty at the given index.
                /// </summary>
                public ParameterProperty this[int index] 
                {
-                       get     { return (ParameterProperty)List[index]; }
-                       set { List[index] = value; }
+                       get
+                       {
+                               if (index < 0 || index >= _count) 
+                               {
+                                       throw new 
ArgumentOutOfRangeException("index");
+                               }
+                               return _innerList[index];
+                       }
+                       set
+                       {
+                               if (index < 0 || index >= _count) 
+                               {
+                                       throw new 
ArgumentOutOfRangeException("index");
+                               }
+                               _innerList[index] = value;
+                       }
                }
+ 
 
                /// <summary>
                /// Add an ParameterProperty
                /// </summary>
                /// <param name="value"></param>
+               /// <returns>Index</returns>
                public int Add(ParameterProperty value) 
                {
-                       return List.Add(value);
+                       Resize(_count + 1);
+                       int index = _count++;
+                       _innerList[index] = value;
+
+                       return index;
                }
 
+ 
                /// <summary>
                /// Add a list of ParameterProperty to the collection
                /// </summary>
                /// <param name="value"></param>
                public void AddRange(ParameterProperty[] value) 
                {
-                       for (int i = 0; i < value.Length; i++) 
+                       for (int i = 0;   i < value.Length; i++) 
                        {
                                Add(value[i]);
                        }
                }
 
+ 
                /// <summary>
                /// Add a list of ParameterProperty to the collection
                /// </summary>
                /// <param name="value"></param>
                public void AddRange(ParameterPropertyCollection value) 
                {
-                       for (int i = 0; i < value.Count; i++) 
+                       for (int i = 0;   i < value.Length; i++) 
                        {
                                Add(value[i]);
                        }
                }
+ 
 
                /// <summary>
                /// Indicate if a ParameterProperty is in the collection
                /// </summary>
-               /// <param name="value">Un(e) ParameterProperty</param>
-               /// <returns>Renvoir vrai s'il/elle appartinet à la 
collection</returns>
+               /// <param name="value">A ParameterProperty</param>
+               /// <returns>True fi is in</returns>
                public bool Contains(ParameterProperty value) 
                {
-                       return List.Contains(value);
+                       for (int i = 0;   i < _count; i++) 
+                       {
+                               
if(_innerList[i].PropertyName==value.PropertyName)
+                               {
+                                       return true;
+                               }
+                       }
+                       return false;
                }
-
+      
 
                /// <summary>
-               /// Copy a collection in a ParameterProperty array
+               /// Insert a ParameterProperty in the collection.
                /// </summary>
-               /// <param name="array">A ParameterProperty array</param>
-               /// <param name="index">Start index of the copy</param>
-               public void CopyTo(ParameterProperty[] array, int index) 
+               /// <param name="index">Index where to insert.</param>
+               /// <param name="value">A ParameterProperty</param>
+               public void Insert(int index, ParameterProperty value) 
                {
-                       List.CopyTo(array, index);
+                       if (index < 0 || index > _count) 
+                       {
+                               throw new ArgumentOutOfRangeException("index");
+                       }
+                       
+                       Resize(_count + 1);
+                       Array.Copy(_innerList, index, _innerList, index + 1, 
_count - index);
+                       _innerList[index] = value;
+                       _count++;
                }
+            
 
                /// <summary>
-               /// Position of the ParameterProperty in the collection.
+               /// Remove a ParameterProperty of the collection.
                /// </summary>
-               /// <param name="value">A ParameterProperty</param>
-               /// <returns>Index found.</returns>
-               public int IndexOf(ParameterProperty value) 
+               public void Remove(ParameterProperty value) 
                {
-                       return List.IndexOf(value);
+                       for(int i = 0; i < _count; i++) 
+                       {
+                               
if(_innerList[i].PropertyName==value.PropertyName)
+                               {
+                                       RemoveAt(i);
+                                       return;
+                               }
+                       }
+
                }
-               
+
                /// <summary>
-               /// Insert a ParameterProperty in the collection.
+               /// Removes a ParameterProperty at the given index. The size of 
the list is
+               /// decreased by one.
                /// </summary>
-               /// <param name="index">Index where to insert.</param>
-               /// <param name="value">A ParameterProperty</param>
-               public void Insert(int index, ParameterProperty value) 
+               /// <param name="index"></param>
+               public void RemoveAt(int index) 
                {
-                       List.Insert(index, value);
+                       if (index < 0 || index >= _count) 
+                       {
+                               throw new ArgumentOutOfRangeException("index");
+                       }
+                       
+                       int remaining = _count - index - 1;
+                                               
+                       if (remaining > 0) 
+                       {
+                               Array.Copy(_innerList, index + 1, _innerList, 
index, remaining);
+                       }
+                       
+                       _count--;
+                       _innerList[_count] = null;
                }
-               
+
                /// <summary>
-               /// Remove a ParameterProperty of the collection.
+               /// Ensures that the capacity of this collection is at least 
the given minimum
+               /// value. If the currect capacity of the list is less than 
min, the
+               /// capacity is increased to twice the current capacity.
                /// </summary>
-               public void Remove(ParameterProperty value) 
+               /// <param name="minSize"></param>
+               private void Resize(int minSize) 
                {
-                       List.Remove(value);
+                       int oldSize = _innerList.Length;
+
+                       if (minSize > oldSize) 
+                       {
+                               ParameterProperty[] oldEntries = _innerList;
+                               int newSize = oldEntries.Length * 
_capacityMultiplier;
+               
+                               if (newSize < minSize) 
+                               {
+                                       newSize = minSize;
+                               }
+                               _innerList = new ParameterProperty[newSize];
+                               Array.Copy(oldEntries, 0, _innerList, 0, 
_count);
+                       }
                }
        }
+
 }
 


Reply via email to