| OLD | NEW |
| 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(); |
| OLD | NEW |