diff options
author | Jason Neufeld <jneufeld@google.com> | 2014-09-16 18:40:11 -0700 |
---|---|---|
committer | Jason Neufeld <jneufeld@google.com> | 2014-09-16 18:40:11 -0700 |
commit | 87bd4029cfdb77196748063277bd7bb172f5ff54 (patch) | |
tree | dea506a915ea4facdad29d36ef3f7a0d0cf933f5 /src/google | |
parent | e1458bba77d190202b98096aec63e5ee18ec0684 (diff) | |
download | protobuf-87bd4029cfdb77196748063277bd7bb172f5ff54.tar.gz protobuf-87bd4029cfdb77196748063277bd7bb172f5ff54.tar.bz2 protobuf-87bd4029cfdb77196748063277bd7bb172f5ff54.zip |
Includes a MessageNano subclass's name's hashCode in hashCode calculations.
In the current implementation, a message with the same amount of null or
equal-valued fields as a different message type will have the same
hashCode. This adds more variety by including the hashCode of the
class's name in the hashCode calculations.
Change-Id: I284e3e6d198ad8037815948d1f65686465ffd623
Signed-off-by: Jason Neufeld <jneufeld@google.com>
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/compiler/javanano/javanano_message.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc index 7a2b4a06..cc44cd35 100644 --- a/src/google/protobuf/compiler/javanano/javanano_message.cc +++ b/src/google/protobuf/compiler/javanano/javanano_message.cc @@ -523,6 +523,7 @@ void MessageGenerator::GenerateHashCode(io::Printer* printer) { printer->Indent(); printer->Print("int result = 17;\n"); + printer->Print("result = 31 * result + getClass().getName().hashCode();\n"); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); field_generators_.get(field).GenerateHashCodeCode(printer); |