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

Side by Side Diff: utils/pub/yaml/yaml_map.dart

Issue 11361190: a === b -> identical(a, b) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « utils/pub/yaml/deep_equals.dart ('k') | utils/template/parser.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * This class wraps behaves almost identically to the normal Dart Map 6 * This class wraps behaves almost identically to the normal Dart Map
7 * implementation, with the following differences: 7 * implementation, with the following differences:
8 * 8 *
9 * * It allows null, NaN, boolean, list, and map keys. 9 * * It allows null, NaN, boolean, list, and map keys.
10 * * It defines `==` structurally. That is, `yamlMap1 == yamlMap2` if they have 10 * * It defines `==` structurally. That is, `yamlMap1 == yamlMap2` if they have
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 } 79 }
80 80
81 /** 81 /**
82 * Returns the hash code for [obj]. This includes null, true, false, maps, and 82 * Returns the hash code for [obj]. This includes null, true, false, maps, and
83 * lists. Also handles self-referential structures. 83 * lists. Also handles self-referential structures.
84 */ 84 */
85 int _hashCode(obj, [List parents]) { 85 int _hashCode(obj, [List parents]) {
86 if (parents == null) { 86 if (parents == null) {
87 parents = []; 87 parents = [];
88 } else if (parents.some((p) => p === obj)) { 88 } else if (parents.some((p) => identical(p, obj))) {
89 return -1; 89 return -1;
90 } 90 }
91 91
92 parents.add(obj); 92 parents.add(obj);
93 try { 93 try {
94 if (obj == null) return 0; 94 if (obj == null) return 0;
95 if (obj == true) return 1; 95 if (obj == true) return 1;
96 if (obj == false) return 2; 96 if (obj == false) return 2;
97 if (obj is Map) { 97 if (obj is Map) {
98 return _hashCode(obj.keys, parents) ^ 98 return _hashCode(obj.keys, parents) ^
99 _hashCode(obj.values, parents); 99 _hashCode(obj.values, parents);
100 } 100 }
101 if (obj is List) { 101 if (obj is List) {
102 // This is probably a really bad hash function, but presumably we'll get t his 102 // This is probably a really bad hash function, but presumably we'll get t his
103 // in the standard library before it actually matters. 103 // in the standard library before it actually matters.
104 int hash = 0; 104 int hash = 0;
105 for (var e in obj) { 105 for (var e in obj) {
106 hash ^= _hashCode(e, parents); 106 hash ^= _hashCode(e, parents);
107 } 107 }
108 return hash; 108 return hash;
109 } 109 }
110 return obj.hashCode; 110 return obj.hashCode;
111 } finally { 111 } finally {
112 parents.removeLast(); 112 parents.removeLast();
113 } 113 }
114 } 114 }
OLDNEW
« no previous file with comments | « utils/pub/yaml/deep_equals.dart ('k') | utils/template/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698