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

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

Issue 11412097: Move hashCode and runtimeType into new interceptors scheme. (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/js_string.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/js_string.dart (revision 15142)
+++ sdk/lib/_internal/compiler/implementation/lib/js_string.dart (working copy)
@@ -132,4 +132,26 @@
}
String toString() => this;
+
+ /**
+ * This is the [Jenkins hash function][1] but using masking to keep
+ * values in SMI range.
+ *
+ * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function
+ */
+ int get hashCode {
+ // TODO(ahe): This method shouldn't have to use JS. Update when our
+ // optimizations are smarter.
+ int hash = 0;
+ for (int i = 0; i < length; i++) {
+ hash = 0x1fffffff & (hash + JS('int', r'#.charCodeAt(#)', this, i));
+ hash = 0x1fffffff & (hash + (0x0007ffff & hash) << 10);
+ hash = JS('int', '# ^ (# >> 6)', hash, hash);
+ }
+ hash = 0x1fffffff & (hash + (0x03ffffff & hash) << 3);
+ hash = JS('int', '# ^ (# >> 11)', hash, hash);
+ return 0x1fffffff & (hash + (0x00003fff & hash) << 15);
+ }
+
+ Type get runtimeType => createRuntimeType('String');
}

Powered by Google App Engine
This is Rietveld 408576698