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

Side by Side Diff: lib/src/protobuf/utils.dart

Issue 1852983002: Fix issues with protobuf equality comparisons (Closed) Base URL: git@github.com:dart-lang/dart-protobuf.git@master
Patch Set: Created 4 years, 8 months 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 unified diff | Download patch
« no previous file with comments | « lib/src/protobuf/field_set.dart ('k') | test/event_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of protobuf; 5 part of protobuf;
6 6
7 // TODO(antonm): reconsider later if PbList should take care of equality. 7 // TODO(antonm): reconsider later if PbList should take care of equality.
8 bool _deepEquals(lhs, rhs) { 8 bool _deepEquals(lhs, rhs) {
9 // Some GeneratedMessages implement Map, so test this first.
10 if ((lhs is GeneratedMessage) && (rhs is GeneratedMessage)) {
Søren Gjesse 2016/04/04 16:06:27 Maybe negate this if to only have one lhs == rhs.
skybrian 2016/04/04 19:38:02 As a style thing, I'd rather repeat the == check t
11 return lhs == rhs;
12 }
9 if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs); 13 if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs);
10 if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs); 14 if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs);
11 if ((lhs is ByteData) && (rhs is ByteData)) { 15 if ((lhs is ByteData) && (rhs is ByteData)) {
12 return _areByteDataEqual(lhs, rhs); 16 return _areByteDataEqual(lhs, rhs);
13 } 17 }
14 return lhs == rhs; 18 return lhs == rhs;
15 } 19 }
16 20
17 bool _areListsEqual(List lhs, List rhs) { 21 bool _areListsEqual(List lhs, List rhs) {
18 range(i) => new Iterable.generate(i, (i) => i); 22 range(i) => new Iterable.generate(i, (i) => i);
19 23
20 if (lhs.length != rhs.length) return false; 24 if (lhs.length != rhs.length) return false;
21 return range(lhs.length).every((i) => _deepEquals(lhs[i], rhs[i])); 25 return range(lhs.length).every((i) => _deepEquals(lhs[i], rhs[i]));
22 } 26 }
23 27
24 bool _areMapsEqual(Map lhs, Map rhs) { 28 bool _areMapsEqual(Map lhs, Map rhs) {
25 if (lhs.length != rhs.length) return false; 29 if (lhs.length != rhs.length) return false;
26 return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key])); 30 return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key]));
27 } 31 }
28 32
29 bool _areByteDataEqual(ByteData lhs, ByteData rhs) { 33 bool _areByteDataEqual(ByteData lhs, ByteData rhs) {
30 asBytes(d) => new Uint8List.view(d.buffer, d.offsetInBytes, d.lengthInBytes); 34 asBytes(d) => new Uint8List.view(d.buffer, d.offsetInBytes, d.lengthInBytes);
31 return _areListsEqual(asBytes(lhs), asBytes(rhs)); 35 return _areListsEqual(asBytes(lhs), asBytes(rhs));
32 } 36 }
33 37
34 List/*<T>*/ sorted/*<T>*/(Iterable/*<T>*/ list) => new List.from(list)..sort(); 38 List/*<T>*/ sorted/*<T>*/(Iterable/*<T>*/ list) => new List.from(list)..sort();
OLDNEW
« no previous file with comments | « lib/src/protobuf/field_set.dart ('k') | test/event_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698