[Mono-list] Array.cs Patch
Dwivedi , Ajay Kumar
AjayKumar.Dwivedi@dresdner-bank.com
Mon, 18 Feb 2002 12:31:12 -0000
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C1B878.264050A0
Content-Type: text/plain;
charset="iso-8859-1"
hi all,
Here is a patch for the Array.cs class.
ChangeLog:
1. Fix for GetUpperBound to return correct values
2. made some Properties virtual
3. Adds IsFixedSize and IsReadOnly properties.
4. changes CreateInstance(Type,int[],int[]) to throw Exception when
third arg is null. InternalCall CreateInstance changed to CreateInstanceImpl
5. Fixed array.GetUpperBound at a couple of places
6. IndexOf and LastIndexOf now use Object.Equals instead of "=="
7. Added two FIXME's in BinarySearch functions.
Happy Hacking,
Ajay
PS: I don't have CVS access and this patch is generated against my own local
CVS which is updated everyday. The diff corresponds to 17th Feb's snapshot.
--
#!!! If anything can go wrong, _FIX_ it. (To hell with MURPHY)
Ajay kumar Dwivedi
------_=_NextPart_000_01C1B878.264050A0
Content-Type: application/octet-stream;
name="Array.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Array.patch"
Index: Array.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/cvsroot/mcs/mcs/class/corlib/System/Array.cs,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Array.cs
--- Array.cs 2002/02/18 05:42:19 1.1.1.1
+++ Array.cs 2002/02/18 11:24:20
@@ -63,18 +63,17 @@
public extern void SetValue (object value, int[] idxs);
=09
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern static Array CreateInstance(Type elementType, int[] =
lengths, int [] bounds);
+ internal extern static Array CreateInstanceImpl(Type elementType, =
int[] lengths, int [] bounds);
=20
- // Methods Implementations
-
- public int Count {
+ // Properties
+ public virtual int Count {
get {
return Length;
}
}
=20
[MonoTODO]
- public bool IsSynchronized {
+ public virtual bool IsSynchronized {
get {
// FIXME?
return false;
@@ -82,13 +81,27 @@
}
=20
[MonoTODO]
- public object SyncRoot {
+ public virtual object SyncRoot {
get {
// FIXME
return null;
}
}
=20
+ public virtual bool IsFixedSize=20
+ {
+ get {
+ return true;
+ }
+ }
+
+ public virtual bool IsReadOnly=20
+ {
+ get{
+ return false;
+ }
+ }
+
[MonoTODO]
public virtual IEnumerator GetEnumerator ()
{
@@ -99,7 +112,7 @@
public int GetUpperBound (int dimension)
{
return GetLowerBound (dimension) +
- GetLength (dimension);
+ GetLength (dimension) - 1;
}
=20
public object GetValue (int idx)
@@ -169,7 +182,7 @@
=09
lengths [0] =3D length;
=09
- return CreateInstance (elementType, lengths, bounds);
+ return CreateInstanceImpl (elementType, lengths, bounds);
}
=09
public static Array CreateInstance(Type elementType, int l1, int l2)
@@ -180,7 +193,7 @@
lengths [0] =3D l1;
lengths [1] =3D l2;
=09
- return CreateInstance (elementType, lengths, bounds);
+ return CreateInstanceImpl (elementType, lengths, bounds);
}
=20
public static Array CreateInstance(Type elementType, int l1, int l2, =
int l3)
@@ -192,14 +205,22 @@
lengths [1] =3D l2;
lengths [2] =3D l3;
=09
- return CreateInstance (elementType, lengths, bounds);
+ return CreateInstanceImpl (elementType, lengths, bounds);
}
=20
public static Array CreateInstance(Type elementType, int[] lengths)
{
int[] bounds =3D null;
=09
- return CreateInstance (elementType, lengths, bounds);
+ return CreateInstanceImpl (elementType, lengths, bounds);
+ }
+
+ public static Array CreateInstance(Type elementType, int[] lengths, =
int [] bounds)
+ {
+ if(bounds =3D=3D null)
+ throw new ArgumentNullException("bounds");
+
+ return CreateInstanceImpl (elementType, lengths, bounds);
}
=20
=09
@@ -233,7 +254,7 @@
if (index < array.GetLowerBound (0) || length < 0)
throw new ArgumentOutOfRangeException ();
=20
- if (index + length > array.GetUpperBound (0))
+ if (index + length > array.GetUpperBound (0) + 1)
throw new ArgumentException ();
=20
if (comparer =3D=3D null && !(value is IComparable))
@@ -243,6 +264,9 @@
// is null and value is not of the same type as the
// elements of array.
=20
+ // FIXME: This is implementing linear search. While it should do a =
binary one
+ // FIXME: Should not throw exception when values are null=20
+
for (int i =3D 0; i < length; i++)=20
{
int result;
@@ -273,17 +297,12 @@
throw new RankException ();
=20
if (index < array.GetLowerBound (0) || length < 0 ||
- index + length > array.GetUpperBound (0))
+ index + length > array.GetUpperBound (0) + 1)
throw new ArgumentOutOfRangeException ();
=20
for (int i =3D 0; i < length; i++)=20
{
- if (array.GetValue(index + i) is bool)
- array.SetValue(false, index + i);
- else if (array.GetValue(index + i) is ValueType)
- array.SetValue(0, index + i);
- else
- array.SetValue(null, index + i);
+ array.SetValue(null, index + i);
}
}
=20
@@ -312,8 +331,8 @@
throw new ArgumentNullException ();
=20
if (source_idx < source.GetLowerBound (0) ||
- source_idx + length > source.GetUpperBound (0) ||
- dest_idx < dest.GetLowerBound (0) || dest_idx + length > =
dest.GetUpperBound (0))
+ source_idx + length > source.GetUpperBound (0) + 1||
+ dest_idx < dest.GetLowerBound (0) || dest_idx + length > =
dest.GetUpperBound (0) + 1)
throw new ArgumentException ();
=20
if (source.Rank !=3D dest.Rank)
@@ -349,7 +368,7 @@
=20
for (int i =3D 0; i < length; i++)
{
- if (array.GetValue(index + i) =3D=3D value)
+ if (array.GetValue(index + i).Equals(value))
return index + i;
}
=20
@@ -377,7 +396,7 @@
=20
for (int i =3D length - 1; i >=3D 0; i--)
{
- if (array.GetValue(index + i) =3D=3D value)
+ if (array.GetValue(index + i).Equals(value))
return index + i;
}
=20
@@ -400,7 +419,7 @@
if (index < array.GetLowerBound (0) || length < 0)
throw new ArgumentOutOfRangeException ();
=20
- if (index + length > array.GetUpperBound (0))
+ if (index + length > array.GetUpperBound (0) + 1)
throw new ArgumentException ();
=20
for (int i =3D 0; i < length/2; i++)
------_=_NextPart_000_01C1B878.264050A0--