[Mono-dev] BitVector32 patch

Scott Peterson lunchtimemama at gmail.com
Tue Aug 26 05:35:01 EDT 2008


OK, the bug is fixed and the fix is committed. I've done up another
patch with the other minor fixes (a few logical things and a few style
things). Patch is attached and inline.

- Scott

Index: class/System/System.Collections.Specialized/BitVector32.cs
===================================================================
--- class/System/System.Collections.Specialized/BitVector32.cs	(revision 111591)
+++ class/System/System.Collections.Specialized/BitVector32.cs	(working copy)
@@ -33,15 +33,13 @@
 using System.Text;

 namespace System.Collections.Specialized {
-	
 	public struct BitVector32 {
-		int bits;
-
 		public struct Section {
 			private short mask;
 			private short offset;
 			
-			internal Section (short mask, short offset) {
+			internal Section (short mask, short offset)
+			{
 				this.mask = mask;
 				this.offset = offset;
 			}
@@ -84,14 +82,12 @@

 			public override int GetHashCode ()
 			{
-				return (((Int16) mask).GetHashCode () << 16) +
-				       ((Int16) offset).GetHashCode ();
+				return mask << offset;
 			}
 			
 			public override string ToString ()
 			{
-				return "Section{0x" + Convert.ToString(mask, 16) +
-				       ", 0x" + Convert.ToString(offset, 16) + "}";
+				return ToString (this);
 			}

 			public static string ToString (Section value)
@@ -106,12 +102,14 @@
 				return b.ToString ();
 			}
 		}
+
+		int bits;
 		
 		// Constructors
 		
 		public BitVector32 (BitVector32 source)
+			: this (source.bits)
 		{
-			bits = source.bits;
 		}

 		public BitVector32 (int init)
@@ -197,10 +195,7 @@
 		
 		public override bool Equals (object o)
 		{
-			if (!(o is BitVector32))
-				return false;
-
-			return bits == ((BitVector32) o).bits;
+			return (o is BitVector32) && bits == ((BitVector32) o).bits;
 		}

 		public override int GetHashCode ()
@@ -218,7 +213,7 @@
 			StringBuilder b = new StringBuilder ();
 			b.Append ("BitVector32{");
 			long mask = (long) 0x80000000;
-			while (mask > 0) {
+			while (mask != 0) {
 				b.Append (((value.bits & mask) == 0) ? '0' : '1');
 				mask >>= 1;
 			}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bitvector32.patch
Type: text/x-diff
Size: 1888 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080826/d4cc70ea/attachment.bin 


More information about the Mono-devel-list mailing list