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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart

Issue 11369181: Update get$hashCode to not use JS for most uses. Also fix issue 6522 where the hashCode of a String… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/interceptors.dart (revision 14782)
+++ sdk/lib/_internal/compiler/implementation/lib/interceptors.dart (working copy)
@@ -630,20 +630,20 @@
// TODO(ahe): This method shouldn't have to use JS. Update when our
// optimizations are smarter.
if (receiver == null) return 0;
- if (receiver is num) return JS('int', r'# & 0x1FFFFFFF', receiver);
+ if (receiver is num) return receiver & 0x1FFFFFFF;
if (receiver is bool) return receiver ? 0x40377024 : 0xc18c0076;
if (isJsArray(receiver)) return Primitives.objectHashCode(receiver);
if (receiver is !String) return UNINTERCEPTED(receiver.hashCode);
int hash = 0;
- int length = JS('int', r'#.length', receiver);
+ int length = receiver.length;
for (int i = 0; i < length; i++) {
hash = 0x1fffffff & (hash + JS('int', r'#.charCodeAt(#)', receiver, i));
- hash = 0x1fffffff & (hash + JS('int', r'# << #', 0x0007ffff & hash, 10));
- hash ^= hash >> 6;
+ hash = 0x1fffffff & (hash + (0x0007ffff & hash) << 10);
+ hash = JS('int', '# ^ (# >> 6)', hash, hash);
}
- hash = 0x1fffffff & (hash + JS('int', r'# << #', 0x03ffffff & hash, 3));
- hash ^= hash >> 11;
- return 0x1fffffff & (hash + JS('int', r'# << #', 0x00003fff & hash, 15));
+ hash = 0x1fffffff & (hash + (0x03ffffff & hash) << 3);
ahe 2012/11/12 20:35:23 Same problem here as on line 646.
+ hash = JS('int', '# ^ (# >> 11)', hash, hash);
+ return 0x1fffffff & (hash + (0x00003fff & hash) << 15);
sra1 2012/11/12 18:20:58 + binds tighter than <<. You want (hash + ((0x000
}
get$charCodes(receiver) {
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/hash_code_test.dart » ('j') | tests/compiler/dart2js_extra/hash_code_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698