浏览代码

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>
Jason Neufeld 11 年之前
父节点
当前提交
87bd4029cf
共有 1 个文件被更改,包括 1 次插入0 次删除
  1. 1 0
      src/google/protobuf/compiler/javanano/javanano_message.cc

+ 1 - 0
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);