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

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

Issue 2012073002: Reduce the number of dynamic calls. (Closed) Base URL: git@github.com:dart-lang/dart-protobuf.git@master
Patch Set: Created 4 years, 6 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
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. 9 // Some GeneratedMessages implement Map, so test this first.
10 if (lhs is GeneratedMessage) return lhs == rhs; 10 if (lhs is GeneratedMessage) return lhs == rhs;
11 if (rhs is GeneratedMessage) return false; 11 if (rhs is GeneratedMessage) return false;
12 if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs); 12 if ((lhs is List) && (rhs is List)) return _areListsEqual(lhs, rhs);
13 if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs); 13 if ((lhs is Map) && (rhs is Map)) return _areMapsEqual(lhs, rhs);
14 if ((lhs is ByteData) && (rhs is ByteData)) { 14 if ((lhs is ByteData) && (rhs is ByteData)) {
15 return _areByteDataEqual(lhs, rhs); 15 return _areByteDataEqual(lhs, rhs);
16 } 16 }
17 return lhs == rhs; 17 return lhs == rhs;
18 } 18 }
19 19
20 bool _areListsEqual(List lhs, List rhs) { 20 bool _areListsEqual(List lhs, List rhs) {
21 range(i) => new Iterable.generate(i, (i) => i);
22
23 if (lhs.length != rhs.length) return false; 21 if (lhs.length != rhs.length) return false;
24 return range(lhs.length).every((i) => _deepEquals(lhs[i], rhs[i])); 22 for (var i = 0; i < lhs.length; i++) {
23 if (!_deepEquals(lhs[i], rhs[i])) return false;
24 }
25 return true;
25 } 26 }
26 27
27 bool _areMapsEqual(Map lhs, Map rhs) { 28 bool _areMapsEqual(Map lhs, Map rhs) {
28 if (lhs.length != rhs.length) return false; 29 if (lhs.length != rhs.length) return false;
29 return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key])); 30 return lhs.keys.every((key) => _deepEquals(lhs[key], rhs[key]));
30 } 31 }
31 32
32 bool _areByteDataEqual(ByteData lhs, ByteData rhs) { 33 bool _areByteDataEqual(ByteData lhs, ByteData rhs) {
33 asBytes(d) => new Uint8List.view(d.buffer, d.offsetInBytes, d.lengthInBytes); 34 asBytes(d) => new Uint8List.view(d.buffer, d.offsetInBytes, d.lengthInBytes);
34 return _areListsEqual(asBytes(lhs), asBytes(rhs)); 35 return _areListsEqual(asBytes(lhs), asBytes(rhs));
35 } 36 }
36 37
37 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
« CHANGELOG.md ('K') | « lib/src/protobuf/generated_message.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698