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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 25099003: Make the implementations of InstanceMirror.hashCode use dart:core's identityHashCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 import "dart:collection"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 295 }
296 296
297 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; 297 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}';
298 298
299 bool operator ==(other) { 299 bool operator ==(other) {
300 return other is _LocalInstanceMirrorImpl && 300 return other is _LocalInstanceMirrorImpl &&
301 identical(_reflectee, other._reflectee); 301 identical(_reflectee, other._reflectee);
302 } 302 }
303 303
304 int get hashCode { 304 int get hashCode {
305 // If the reflectee is a double or bignum, use the base hashCode to preserve
306 // the illusion that boxed numbers with the same value are identical. If the
307 // reflectee is a Smi, use the base hashCode because Object.hashCode does
308 // not work for non-heap objects. Otherwise, use Object.hashCode to maintain
309 // correctness even if a user-defined hashCode returns different values for
310 // successive invocations.
311 var h = _reflectee is num ? _reflectee.hashCode : _identityHash(_reflectee);
312 // Avoid hash collisions with the reflectee. This constant is in Smi range 305 // Avoid hash collisions with the reflectee. This constant is in Smi range
313 // and happens to be the inner padding from RFC 2104. 306 // and happens to be the inner padding from RFC 2104.
314 return h ^ 0x36363636; 307 return identityHashCode(_reflectee) ^ 0x36363636;
315 } 308 }
316 309
317 static _identityHash(reflectee)
318 native "InstanceMirror_identityHash";
319
320 // Override to include the receiver in the arguments. 310 // Override to include the receiver in the arguments.
321 InstanceMirror invoke(Symbol memberName, 311 InstanceMirror invoke(Symbol memberName,
322 List positionalArguments, 312 List positionalArguments,
323 [Map<Symbol, dynamic> namedArguments]) { 313 [Map<Symbol, dynamic> namedArguments]) {
324 int numPositionalArguments = positionalArguments.length + 1; // Receiver. 314 int numPositionalArguments = positionalArguments.length + 1; // Receiver.
325 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 315 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
326 int numArguments = numPositionalArguments + numNamedArguments; 316 int numArguments = numPositionalArguments + numNamedArguments;
327 List arguments = new List(numArguments); 317 List arguments = new List(numArguments);
328 arguments[0] = _reflectee; // Receiver. 318 arguments[0] = _reflectee; // Receiver.
329 arguments.setRange(1, numPositionalArguments, positionalArguments); 319 arguments.setRange(1, numPositionalArguments, positionalArguments);
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 if (typeMirror == null) { 1321 if (typeMirror == null) {
1332 typeMirror = makeLocalTypeMirror(key); 1322 typeMirror = makeLocalTypeMirror(key);
1333 _instanitationCache[key] = typeMirror; 1323 _instanitationCache[key] = typeMirror;
1334 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1324 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1335 _declarationCache[key] = typeMirror; 1325 _declarationCache[key] = typeMirror;
1336 } 1326 }
1337 } 1327 }
1338 return typeMirror; 1328 return typeMirror;
1339 } 1329 }
1340 } 1330 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698