Skip to content

Sync changes from internal repo. #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.children
.dart_tool/
.idea
.packages
.pub
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.7.2

* Fix hashing for PbList.

## 0.7.1

* Fix type in PbList.fold() for Dart 2.
Expand Down
13 changes: 6 additions & 7 deletions lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class _FieldSet {

void hashEnumList(PbList enums) {
for (ProtobufEnum enm in enums) {
hash = (31 * hash + enm.value) & 0x3fffffff;
hash = 0x1fffffff & ((31 * hash) + enm.value);
}
}

Expand All @@ -422,15 +422,14 @@ class _FieldSet {
if (value is List && value.isEmpty) {
return; // It's either repeated or an empty byte array.
}
hash = ((37 * hash) + fi.tagNumber) & 0x3fffffff;
hash = 0x1fffffff & ((37 * hash) + fi.tagNumber);
if (!_isEnum(fi.type)) {
// TODO(sgjesse): Remove 'as Object' here when issue 14951 is fixed.
hash = ((53 * hash) + (value as Object).hashCode) & 0x3fffffff;
hash = 0x1fffffff & ((53 * hash) + value.hashCode);
} else if (fi.isRepeated) {
hashEnumList(value);
} else {
ProtobufEnum enm = value;
hash = ((53 * hash) + enm.value) & 0x3fffffff;
hash = 0x1fffffff & ((53 * hash) + enm.value);
}
}

Expand All @@ -449,12 +448,12 @@ class _FieldSet {
// Generate hash.
hash = 41;
// Hash with descriptor.
hash = ((19 * hash) + _meta.hashCode) & 0x3fffffff;
hash = 0x1fffffff & ((19 * hash) + _meta.hashCode);
// Hash with fields.
hashEachField();
// Hash with unknown fields.
if (hasUnknownFields) {
hash = ((29 * hash) + _unknownFields.hashCode) & 0x3fffffff;
hash = 0x1fffffff & ((29 * hash) + _unknownFields.hashCode);
}
return hash;
}
Expand Down
13 changes: 6 additions & 7 deletions lib/src/protobuf/pb_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ class PbList<E> extends ListBase<E> {
int get hashCode {
int hash = 0;
for (final value in _wrappedList) {
hash = (hash + value.hashCode) & 0x3fffffff;
hash = (hash + hash << 10) & 0x3fffffff;
hash = (hash ^ hash >> 6) & 0x3fffffff;
hash = 0x1fffffff & (hash + value.hashCode);
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
hash = hash ^ (hash >> 6);
}
hash = (hash + hash << 3) & 0x3fffffff;
hash = (hash ^ hash >> 11) & 0x3fffffff;
hash = (hash + hash << 15) & 0x3fffffff;
return hash;
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}

/// Returns an [Iterator] for the list.
Expand Down
24 changes: 12 additions & 12 deletions lib/src/protobuf/unknown_field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class UnknownFieldSet {
int get hashCode {
int hash = 0;
_fields.forEach((int number, Object value) {
hash = ((37 * hash) + number) & 0x3fffffff;
hash = ((53 * hash) + value.hashCode) & 0x3fffffff;
hash = 0x1fffffff & ((37 * hash) + number);
hash = 0x1fffffff & ((53 * hash) + value.hashCode);
});
return hash;
}
Expand Down Expand Up @@ -193,25 +193,25 @@ class UnknownFieldSetField {
int hash = 0;
for (final value in lengthDelimited) {
for (int i = 0; i < value.length; i++) {
hash = (hash + value[i]) & 0x3fffffff;
hash = (hash + hash << 10) & 0x3fffffff;
hash = (hash ^ hash >> 6) & 0x3fffffff;
hash = 0x1fffffff & (hash + value[i]);
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
hash = hash ^ (hash >> 6);
}
hash = (hash + hash << 3) & 0x3fffffff;
hash = (hash ^ hash >> 11) & 0x3fffffff;
hash = (hash + hash << 15) & 0x3fffffff;
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
hash = hash ^ (hash >> 11);
hash = 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
for (final value in varints) {
hash = (hash + 7 * value.hashCode) & 0x3fffffff;
hash = 0x1fffffff & (hash + (7 * value.hashCode));
}
for (final value in fixed32s) {
hash = (hash + 37 * value.hashCode) & 0x3fffffff;
hash = 0x1fffffff & (hash + (37 * value.hashCode));
}
for (final value in fixed64s) {
hash = (hash + 53 * value.hashCode) & 0x3fffffff;
hash = 0x1fffffff & (hash + (53 * value.hashCode));
}
for (final value in groups) {
hash = (hash + value.hashCode) & 0x3fffffff;
hash = 0x1fffffff & (hash + value.hashCode);
}
return hash;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: protobuf
version: 0.7.1
version: 0.7.2
author: Dart Team <misc@dartlang.org>
description: Runtime library for protocol buffers support.
homepage: https://github.com/dart-lang/protobuf
Expand Down