Commit 0d409f52 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Directly use C++ builtin of ArrayPush for String.prototype.split.

R=svenpanne@chromium.org
BUG=v8:2737

Review URL: https://codereview.chromium.org/17283007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15223 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 640353d0
...@@ -644,6 +644,8 @@ function StringSplit(separator, limit) { ...@@ -644,6 +644,8 @@ function StringSplit(separator, limit) {
} }
var ArrayPushBuiltin = $Array.prototype.push;
function StringSplitOnRegExp(subject, separator, limit, length) { function StringSplitOnRegExp(subject, separator, limit, length) {
%_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]);
...@@ -657,19 +659,21 @@ function StringSplitOnRegExp(subject, separator, limit, length) { ...@@ -657,19 +659,21 @@ function StringSplitOnRegExp(subject, separator, limit, length) {
var currentIndex = 0; var currentIndex = 0;
var startIndex = 0; var startIndex = 0;
var startMatch = 0; var startMatch = 0;
var result = new InternalArray(); var result = [];
outer_loop: outer_loop:
while (true) { while (true) {
if (startIndex === length) { if (startIndex === length) {
result.push(%_SubString(subject, currentIndex, length)); %_CallFunction(result, %_SubString(subject, currentIndex, length),
ArrayPushBuiltin);
break; break;
} }
var matchInfo = DoRegExpExec(separator, subject, startIndex); var matchInfo = DoRegExpExec(separator, subject, startIndex);
if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) { if (matchInfo == null || length === (startMatch = matchInfo[CAPTURE0])) {
result.push(%_SubString(subject, currentIndex, length)); %_CallFunction(result, %_SubString(subject, currentIndex, length),
ArrayPushBuiltin);
break; break;
} }
var endIndex = matchInfo[CAPTURE1]; var endIndex = matchInfo[CAPTURE1];
...@@ -680,7 +684,8 @@ function StringSplitOnRegExp(subject, separator, limit, length) { ...@@ -680,7 +684,8 @@ function StringSplitOnRegExp(subject, separator, limit, length) {
continue; continue;
} }
result.push(%_SubString(subject, currentIndex, startMatch)); %_CallFunction(result, %_SubString(subject, currentIndex, startMatch),
ArrayPushBuiltin);
if (result.length === limit) break; if (result.length === limit) break;
...@@ -689,16 +694,17 @@ function StringSplitOnRegExp(subject, separator, limit, length) { ...@@ -689,16 +694,17 @@ function StringSplitOnRegExp(subject, separator, limit, length) {
var start = matchInfo[i++]; var start = matchInfo[i++];
var end = matchInfo[i++]; var end = matchInfo[i++];
if (end != -1) { if (end != -1) {
result.push(%_SubString(subject, start, end)); %_CallFunction(result, %_SubString(subject, start, end),
ArrayPushBuiltin);
} else { } else {
result.push(void 0); %_CallFunction(result, void 0, ArrayPushBuiltin);
} }
if (result.length === limit) break outer_loop; if (result.length === limit) break outer_loop;
} }
startIndex = currentIndex = endIndex; startIndex = currentIndex = endIndex;
} }
return %MoveArrayContents(result, []); return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment