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

Unified Diff: src/string.js

Issue 401783003: Optimize algorithm for String.prototype.repeat(), fix value caching in others (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Clarify with comments Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« src/harmony-string.js ('K') | « src/harmony-string.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string.js
diff --git a/src/string.js b/src/string.js
index 0d5ed0fc4297c49b0f79917de5a9e6b6a2758c4d..04688bda49401d766834132162edfddbe4104d9c 100644
--- a/src/string.js
+++ b/src/string.js
@@ -711,12 +711,13 @@ function StringSubstr(start, n) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
var s = TO_STRING_INLINE(this);
+ var s_len = s.length;
var len;
// Correct n: If not given, set to string length; if explicitly
// set to undefined, zero, or negative, returns empty string.
if (IS_UNDEFINED(n)) {
- len = s.length;
+ len = s_len;
} else {
len = TO_INTEGER(n);
if (len <= 0) return '';
@@ -730,17 +731,17 @@ function StringSubstr(start, n) {
start = TO_INTEGER(start);
// If positive, and greater than or equal to the string length,
// return empty string.
- if (start >= s.length) return '';
+ if (start >= s_len) return '';
// If negative and absolute value is larger than the string length,
// use zero.
if (start < 0) {
- start += s.length;
+ start += s_len;
if (start < 0) start = 0;
}
}
var end = start + len;
- if (end > s.length) end = s.length;
+ if (end > s_len) end = s_len;
return %_SubString(s, start, end);
}
« src/harmony-string.js ('K') | « src/harmony-string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698