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

Unified Diff: src/string.js

Issue 519061: Improve performance of Array.prototype.join and String.prototype.substring... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 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
Index: src/string.js
===================================================================
--- src/string.js (revision 3544)
+++ src/string.js (working copy)
@@ -505,7 +505,7 @@
// ECMA-262 section 15.5.4.14
function StringSplit(separator, limit) {
var subject = ToString(this);
- limit = (limit === void 0) ? 0xffffffff : ToUint32(limit);
+ limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
if (limit === 0) return [];
// ECMA-262 says that if separator is undefined, the result should
@@ -604,22 +604,30 @@
// ECMA-262 section 15.5.4.15
function StringSubstring(start, end) {
- var s = ToString(this);
+ var s = this;
+ if (!IS_STRING(s)) s = ToString(s);
var s_len = s.length;
+
var start_i = TO_INTEGER(start);
+ if (start_i < 0) {
+ start_i = 0;
+ } else if (start_i > s_len) {
+ start_i = s_len;
+ }
+
var end_i = s_len;
- if (!IS_UNDEFINED(end))
+ if (!IS_UNDEFINED(end)) {
end_i = TO_INTEGER(end);
-
- if (start_i < 0) start_i = 0;
- if (start_i > s_len) start_i = s_len;
- if (end_i < 0) end_i = 0;
- if (end_i > s_len) end_i = s_len;
-
- if (start_i > end_i) {
- var tmp = end_i;
- end_i = start_i;
- start_i = tmp;
+ if (end_i > s_len) {
+ end_i = s_len;
+ } else {
+ if (end_i < 0) end_i = 0;
+ if (start_i > end_i) {
+ var tmp = end_i;
+ end_i = start_i;
+ start_i = tmp;
+ }
+ }
}
return SubString(s, start_i, end_i);
@@ -790,21 +798,14 @@
}
-// StringBuilder support.
-
-function StringBuilder() {
- this.elements = new $Array();
-}
-
-
+// ReplaceResultBuilder support.
function ReplaceResultBuilder(str) {
this.elements = new $Array();
this.special_string = str;
}
-ReplaceResultBuilder.prototype.add =
-StringBuilder.prototype.add = function(str) {
+ReplaceResultBuilder.prototype.add = function(str) {
if (!IS_STRING(str)) str = ToString(str);
if (str.length > 0) {
var elements = this.elements;
@@ -828,13 +829,9 @@
}
-StringBuilder.prototype.generate = function() {
- return %StringBuilderConcat(this.elements, "");
-}
-
-
ReplaceResultBuilder.prototype.generate = function() {
- return %StringBuilderConcat(this.elements, this.special_string);
+ var elements = this.elements;
+ return %StringBuilderConcat(elements, elements.length, this.special_string);
}

Powered by Google App Engine
This is Rietveld 408576698