Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Unified Diff: lib/unknown_field_set.dart

Issue 64753003: Update hashCode to hash the entire message (Closed) Base URL: https://github.com/dart-lang/dart-protobuf.git@master
Patch Set: Update version number Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/pb_list.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unknown_field_set.dart
diff --git a/lib/unknown_field_set.dart b/lib/unknown_field_set.dart
index f35cbc5806d68b9e45424c11d1d438c8b143e15a..76caa746f51e2fbd260bfadda7a54ca3b441b45b 100644
--- a/lib/unknown_field_set.dart
+++ b/lib/unknown_field_set.dart
@@ -120,7 +120,14 @@ class UnknownFieldSet {
return _areMapsEqual(o._fields, _fields);
}
- int get hashCode => _fields.hashCode;
+ int get hashCode {
+ int hash = 0;
+ _fields.forEach((number, value) {
+ hash = ((37 * hash) + number) & 0x3fffffff;
+ hash = ((53 * hash) + value.hashCode) & 0x3fffffff;
+ });
+ return hash;
+ }
String toString() => _toString('');
@@ -181,7 +188,28 @@ class UnknownFieldSetField {
return true;
}
- int get hashCode => lengthDelimited.hashCode;
+ int get hashCode {
+ int hash = 0;
+ lengthDelimited.forEach((value) {
+ for (int i = 0; i < value.length; i++) {
+ hash = (hash + value[i]) & 0x3fffffff;
+ hash = (hash + hash << 10) & 0x3fffffff;
+ hash = (hash ^ hash >> 6) & 0x3fffffff;
+ }
+ hash = (hash + hash << 3) & 0x3fffffff;
+ hash = (hash ^ hash >> 11) & 0x3fffffff;
+ hash = (hash + hash << 15) & 0x3fffffff;
+ });
+ varints.forEach(
+ (value) => hash = (hash + 7 * value.hashCode) & 0x3fffffff);
+ fixed32s.forEach(
+ (value) => hash = (hash + 37 * value.hashCode) & 0x3fffffff);
+ fixed64s.forEach(
+ (value) => hash = (hash + 53 * value.hashCode) & 0x3fffffff);
+ groups.forEach(
+ (value) => hash = (hash + value.hashCode) & 0x3fffffff);
+ return hash;
+ }
List get values => []
..addAll(lengthDelimited)
« no previous file with comments | « lib/pb_list.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698