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

Unified Diff: compiler/lib/implementation/string.js

Issue 8511023: Use strict when possible. Don't even try to cache the hashcode for strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 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 | « compiler/lib/implementation/number.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/lib/implementation/string.js
diff --git a/compiler/lib/implementation/string.js b/compiler/lib/implementation/string.js
index e49b8ea3d4e2e0afba3020385cc315b8295ad560..75e249236354d1e07b54a41c21cf5b04562825c0 100644
--- a/compiler/lib/implementation/string.js
+++ b/compiler/lib/implementation/string.js
@@ -3,26 +3,32 @@
// BSD-style license that can be found in the LICENSE file.
function native_StringImplementation__indexOperator(index) {
+ "use strict";
return this[index];
}
function native_StringImplementation__charCodeAt(index) {
+ "use strict";
return this.charCodeAt(index);
}
function native_StringImplementation_get$length() {
+ "use strict";
return this.length;
}
function native_StringImplementation_EQ(other) {
+ "use strict";
return typeof other == 'string' && this == other;
}
function native_StringImplementation__nativeIndexOf(other, startIndex) {
+ "use strict";
return this.indexOf(other, startIndex);
}
function native_StringImplementation__nativeLastIndexOf(other, fromIndex) {
+ "use strict";
if (other == "") {
return Math.min(this.length, fromIndex);
}
@@ -30,19 +36,23 @@ function native_StringImplementation__nativeLastIndexOf(other, fromIndex) {
}
function native_StringImplementation_concat(other) {
+ "use strict";
return this.concat(other);
}
function native_StringImplementation__substringUnchecked(startIndex, endIndex) {
+ "use strict";
return this.substring(startIndex, endIndex);
}
function native_StringImplementation_trim() {
+ "use strict";
if (this.trim) return this.trim();
return this.replace(new RegExp("^[\s]+|[\s]+$", "g"), "");
}
function native_StringImplementation__replace(from, to) {
+ "use strict";
if ($isString(from)) {
return this.replace(from, to);
} else {
@@ -51,6 +61,7 @@ function native_StringImplementation__replace(from, to) {
}
function native_StringImplementation__replaceAll(from, to) {
+ "use strict";
if ($isString(from)) {
var regexp = new RegExp(
from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g');
@@ -62,6 +73,7 @@ function native_StringImplementation__replaceAll(from, to) {
}
function native_StringImplementation__split(pattern) {
+ "use strict";
if ($isString(pattern)) {
return this.split(pattern);
} else {
@@ -70,32 +82,36 @@ function native_StringImplementation__split(pattern) {
}
function native_StringImplementation_toLowerCase() {
+ "use strict";
return this.toLowerCase();
}
function native_StringImplementation_toUpperCase() {
+ "use strict";
return this.toUpperCase();
}
// Inherited from Hashable.
function native_StringImplementation_hashCode() {
- if (this.hash_ === undefined) {
- for (var i = 0; i < this.length; i++) {
- var ch = this.charCodeAt(i);
- this.hash_ += ch;
- this.hash_ += this.hash_ << 10;
- this.hash_ ^= this.hash_ >> 6;
- }
-
- this.hash_ += this.hash_ << 3;
- this.hash_ ^= this.hash_ >> 11;
- this.hash_ += this.hash_ << 15;
- this.hash_ = this.hash_ & ((1 << 29) - 1);
+ "use strict";
sra1 2011/11/22 18:13:39 What is the benefit of "use strict" in this and th
floitsch 2011/11/23 09:21:54 "use strict" doesn't wrap the object. So (3).hashC
+ var hash = 0;
+ for (var i = 0; i < this.length; i++) {
+ var ch = this.charCodeAt(i);
+ hash += ch;
+ hash += hash << 10;
sra1 2011/11/22 18:13:39 The result of += can be outside the 32-bit range o
floitsch 2011/11/23 09:21:54 Given that we can't store the hash we should rethi
+ hash ^= hash >> 6;
}
- return this.hash_;
+
+ hash += hash << 3;
+ hash ^= hash >> 11;
+ hash += hash << 15;
+ hash = hash & ((1 << 29) - 1);
+
+ return hash;
}
function native_StringImplementation_toString() {
+ "use strict";
// Return the primitive string of this String object.
return String(this);
}
@@ -103,12 +119,14 @@ function native_StringImplementation_toString() {
// TODO(floitsch): If we allow comparison operators on the String class we
// should move this function into dart world.
function native_StringImplementation_compareTo(other) {
+ "use strict";
if (this == other) return 0;
if (this < other) return -1;
return 1;
}
function native_StringImplementation__newFromValues(array) {
+ "use strict";
if (!(array instanceof Array)) {
var length = native__ListJsUtil__listLength(array);
var tmp = new Array(length);
« no previous file with comments | « compiler/lib/implementation/number.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698