Browse Source

Making ByteString.bytes internal, to allow faster access to the raw bytes.
Fixing ByteString.GetHashCode to create good hash code.

Ayende Rahien 15 năm trước cách đây
mục cha
commit
e3aff478fd
1 tập tin đã thay đổi với 6 bổ sung5 xóa
  1. 6 5
      src/ProtocolBuffers/ByteString.cs

+ 6 - 5
src/ProtocolBuffers/ByteString.cs

@@ -46,7 +46,7 @@ namespace Google.ProtocolBuffers {
 
     private static readonly ByteString empty = new ByteString(new byte[0]);
 
-    private readonly byte[] bytes;
+    internal readonly byte[] bytes;
 
     /// <summary>
     /// Constructs a new ByteString from the given byte array. The array is
@@ -154,10 +154,11 @@ namespace Google.ProtocolBuffers {
     }
 
     public override int GetHashCode() {
-      int ret = 23;
-      foreach (byte b in bytes) {
-        ret = (ret << 8) | b;
-      }
+      int ret = 23;
+	  for (int i = 0; i < bytes.Length; i++)
+	  {
+		  ret = (ret * 23) ^ bytes[i];
+	  }
       return ret;
     }