diff options
author | Brian Duff <bduff@google.com> | 2013-10-15 18:35:44 -0700 |
---|---|---|
committer | Max Cai <maxtroy@google.com> | 2013-10-25 16:06:21 +0100 |
commit | ccc48faf20dbf3b3cddcffe78d198876d543529b (patch) | |
tree | 82a2f42e9d464661152539821093b14fbc068189 /src/google/protobuf/compiler/javanano/javanano_helpers.cc | |
parent | 42be1e79ccd670be36220222936aa7cacc6856f6 (diff) | |
download | external_protobuf-ccc48faf20dbf3b3cddcffe78d198876d543529b.zip external_protobuf-ccc48faf20dbf3b3cddcffe78d198876d543529b.tar.gz external_protobuf-ccc48faf20dbf3b3cddcffe78d198876d543529b.tar.bz2 |
Implement hashCode() and equals() behind a generator option.
The option is only called 'generate_equals' because:
- equals() is the main thing; hashCode() is there only to
complement equals();
- it's shorter;
- toString() should not be included in this option because
it's more for debugging and it's more likely to stop
ProGuard from working well.
Also shortened the "has bit" expression; was
((bitField & mask) == mask), now ((bitField & mask) != 0).
Both the Java code and the bytecode are slightly shorter.
Change-Id: Ic309a08a60883bf454eb6612679aa99611620e76
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_helpers.cc')
-rw-r--r-- | src/google/protobuf/compiler/javanano/javanano_helpers.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/src/google/protobuf/compiler/javanano/javanano_helpers.cc index ed6dbd7..95ee670 100644 --- a/src/google/protobuf/compiler/javanano/javanano_helpers.cc +++ b/src/google/protobuf/compiler/javanano/javanano_helpers.cc @@ -482,7 +482,7 @@ string GenerateGetBit(int bit_index) { int bit_in_var_index = bit_index % 32; string mask = kBitMasks[bit_in_var_index]; - string result = "((" + var_name + " & " + mask + ") == " + mask + ")"; + string result = "((" + var_name + " & " + mask + ") != 0)"; return result; } @@ -504,11 +504,22 @@ string GenerateClearBit(int bit_index) { return result; } +string GenerateDifferentBit(int bit_index) { + string var_name = GetBitFieldNameForBit(bit_index); + int bit_in_var_index = bit_index % 32; + + string mask = kBitMasks[bit_in_var_index]; + string result = "((" + var_name + " & " + mask + + ") != (other." + var_name + " & " + mask + "))"; + return result; +} + void SetBitOperationVariables(const string name, int bitIndex, map<string, string>* variables) { (*variables)["get_" + name] = GenerateGetBit(bitIndex); (*variables)["set_" + name] = GenerateSetBit(bitIndex); (*variables)["clear_" + name] = GenerateClearBit(bitIndex); + (*variables)["different_" + name] = GenerateDifferentBit(bitIndex); } } // namespace javanano |