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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/interceptors.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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/lib/js_array.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/interceptors.dart (revision 15142)
+++ sdk/lib/_internal/compiler/implementation/lib/interceptors.dart (working copy)
@@ -78,6 +78,8 @@
class JSBool implements bool {
const JSBool();
String toString() => JS('String', r'String(#)', this);
+ int get hashCode => this ? 0x40377024 : 0xc18c0076;
+ Type get runtimeType => createRuntimeType('bool');
}
/**
@@ -86,48 +88,6 @@
class JSNull implements Null {
const JSNull();
String toString() => 'null';
+ int get hashCode => 0;
+ Type get runtimeType => createRuntimeType('Null');
}
-
-/**
- * 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
- */
-get$hashCode(receiver) {
- // 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 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 = receiver.length;
- for (int i = 0; i < length; i++) {
- hash = 0x1fffffff & (hash + JS('int', r'#.charCodeAt(#)', receiver, 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);
-}
-
-get$runtimeType(receiver) {
- if (receiver is int) {
- return createRuntimeType('int');
- } else if (receiver is String) {
- return createRuntimeType('String');
- } else if (receiver is double) {
- return createRuntimeType('double');
- } else if (receiver is bool) {
- return createRuntimeType('bool');
- } else if (receiver == null) {
- return createRuntimeType('Null');
- } else if (isJsArray(receiver)) {
- return createRuntimeType('List');
- } else {
- return UNINTERCEPTED(receiver.runtimeType);
- }
-}
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/lib/js_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698