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

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: tweak _deepEquals, improve tests 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) return lhs == rhs;
11 if (rhs is GeneratedMessage) return false;
9 if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs); 12 if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs);
10 if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs); 13 if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs);
11 if ((lhs is ByteData) && (rhs is ByteData)) { 14 if ((lhs is ByteData) && (rhs is ByteData)) {
12 return _areByteDataEqual(lhs, rhs); 15 return _areByteDataEqual(lhs, rhs);
13 } 16 }
14 return lhs == rhs; 17 return lhs == rhs;
15 } 18 }
16 19
17 bool _areListsEqual(List lhs, List rhs) { 20 bool _areListsEqual(List lhs, List rhs) {
18 range(i) => new Iterable.generate(i, (i) => i); 21 range(i) => new Iterable.generate(i, (i) => i);
19 22
20 if (lhs.length != rhs.length) return false; 23 if (lhs.length != rhs.length) return false;
21 return range(lhs.length).every((i) => _deepEquals(lhs[i], rhs[i])); 24 return range(lhs.length).every((i) => _deepEquals(lhs[i], rhs[i]));
22 } 25 }
23 26
24 bool _areMapsEqual(Map lhs, Map rhs) { 27 bool _areMapsEqual(Map lhs, Map rhs) {
25 if (lhs.length != rhs.length) return false; 28 if (lhs.length != rhs.length) return false;
26 return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key])); 29 return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key]));
27 } 30 }
28 31
29 bool _areByteDataEqual(ByteData lhs, ByteData rhs) { 32 bool _areByteDataEqual(ByteData lhs, ByteData rhs) {
30 asBytes(d) => new Uint8List.view(d.buffer, d.offsetInBytes, d.lengthInBytes); 33 asBytes(d) => new Uint8List.view(d.buffer, d.offsetInBytes, d.lengthInBytes);
31 return _areListsEqual(asBytes(lhs), asBytes(rhs)); 34 return _areListsEqual(asBytes(lhs), asBytes(rhs));
32 } 35 }
33 36
34 List/*<T>*/ sorted/*<T>*/(Iterable/*<T>*/ list) => new List.from(list)..sort(); 37 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