aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-07-04 14:40:24 +0100
committerJon Skeet <jonskeet@google.com>2015-07-16 09:36:31 +0100
commit8d47ec4f3e3368c5f4e7ac195f20978abc8a692f (patch)
tree2800688fd666bccedddf90ae0fc7ca9941649bf4 /csharp/src/ProtocolBuffers
parentb2ac868493742327b2ebbcacd97947126f8841f7 (diff)
downloadprotobuf-8d47ec4f3e3368c5f4e7ac195f20978abc8a692f.tar.gz
protobuf-8d47ec4f3e3368c5f4e7ac195f20978abc8a692f.tar.bz2
protobuf-8d47ec4f3e3368c5f4e7ac195f20978abc8a692f.zip
Fixes to ByteString's equality handling.
Diffstat (limited to 'csharp/src/ProtocolBuffers')
-rw-r--r--csharp/src/ProtocolBuffers/ByteString.cs35
1 files changed, 15 insertions, 20 deletions
diff --git a/csharp/src/ProtocolBuffers/ByteString.cs b/csharp/src/ProtocolBuffers/ByteString.cs
index 738f020e..329f47f6 100644
--- a/csharp/src/ProtocolBuffers/ByteString.cs
+++ b/csharp/src/ProtocolBuffers/ByteString.cs
@@ -212,11 +212,22 @@ namespace Google.Protobuf
{
return true;
}
- if (ReferenceEquals(lhs, null))
+ if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))
{
return false;
}
- return lhs.Equals(rhs);
+ if (lhs.bytes.Length != rhs.bytes.Length)
+ {
+ return false;
+ }
+ for (int i = 0; i < lhs.Length; i++)
+ {
+ if (rhs.bytes[i] != lhs.bytes[i])
+ {
+ return false;
+ }
+ }
+ return true;
}
public static bool operator !=(ByteString lhs, ByteString rhs)
@@ -228,12 +239,7 @@ namespace Google.Protobuf
public override bool Equals(object obj)
{
- ByteString other = obj as ByteString;
- if (obj == null)
- {
- return false;
- }
- return Equals(other);
+ return this == (obj as ByteString);
}
public override int GetHashCode()
@@ -248,18 +254,7 @@ namespace Google.Protobuf
public bool Equals(ByteString other)
{
- if (other.bytes.Length != bytes.Length)
- {
- return false;
- }
- for (int i = 0; i < bytes.Length; i++)
- {
- if (other.bytes[i] != bytes[i])
- {
- return false;
- }
- }
- return true;
+ return this == other;
}
/// <summary>