mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 943126 - Fast-path for String.split(""). r=h4writer
This commit is contained in:
parent
8f9eb02165
commit
dfbafafce3
16
js/src/jit-test/tests/basic/bug943126.js
Normal file
16
js/src/jit-test/tests/basic/bug943126.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Test fast-path for String.split("").
|
||||||
|
|
||||||
|
load(libdir + 'eqArrayHelper.js');
|
||||||
|
|
||||||
|
assertEqArray("".split(""), []);
|
||||||
|
assertEqArray("a".split(""), ["a"]);
|
||||||
|
assertEqArray("abc".split(""), ["a", "b", "c"]);
|
||||||
|
|
||||||
|
assertEqArray("abcd".split("", 2), ["a", "b"]);
|
||||||
|
assertEqArray("abcd".split("", 0), []);
|
||||||
|
assertEqArray("abcd".split("", -1), ["a", "b", "c", "d"]);
|
||||||
|
|
||||||
|
// Note: V8 disagrees about this one, but we are correct by ecma-262 15.5.4.14 part 9.
|
||||||
|
assertEqArray("abcd".split(undefined, 0), []);
|
||||||
|
|
||||||
|
assertEqArray("abcd".split(undefined, 1), ["abcd"]);
|
@ -2645,7 +2645,8 @@ AppendSubstrings(JSContext *cx, Handle<JSStableString*> stableStr,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
/* Appending to the rope permanently roots the substring. */
|
/* Appending to the rope permanently roots the substring. */
|
||||||
rope.append(part);
|
if (!rope.append(part))
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rope.result();
|
return rope.result();
|
||||||
@ -3132,6 +3133,31 @@ SplitHelper(JSContext *cx, Handle<JSLinearString*> str, uint32_t limit, const Ma
|
|||||||
return NewDenseCopiedArray(cx, splits.length(), splits.begin());
|
return NewDenseCopiedArray(cx, splits.length(), splits.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fast-path for splitting a string into a character array via split("").
|
||||||
|
static ArrayObject *
|
||||||
|
CharSplitHelper(JSContext *cx, Handle<JSLinearString*> str, uint32_t limit)
|
||||||
|
{
|
||||||
|
size_t strLength = str->length();
|
||||||
|
if (strLength == 0)
|
||||||
|
return NewDenseEmptyArray(cx);
|
||||||
|
|
||||||
|
js::StaticStrings &staticStrings = cx->runtime()->staticStrings;
|
||||||
|
uint32_t resultlen = (limit < strLength ? limit : strLength);
|
||||||
|
|
||||||
|
AutoValueVector splits(cx);
|
||||||
|
if (!splits.reserve(resultlen))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < resultlen; ++i) {
|
||||||
|
JSString *sub = staticStrings.getUnitStringForElement(cx, str, i);
|
||||||
|
if (!sub)
|
||||||
|
return nullptr;
|
||||||
|
splits.infallibleAppend(StringValue(sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewDenseCopiedArray(cx, splits.length(), splits.begin());
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3274,8 +3300,12 @@ js::str_split(JSContext *cx, unsigned argc, Value *vp)
|
|||||||
/* Steps 11-15. */
|
/* Steps 11-15. */
|
||||||
RootedObject aobj(cx);
|
RootedObject aobj(cx);
|
||||||
if (!re.initialized()) {
|
if (!re.initialized()) {
|
||||||
|
if (sepstr->length() == 0) {
|
||||||
|
aobj = CharSplitHelper(cx, linearStr, limit);
|
||||||
|
} else {
|
||||||
SplitStringMatcher matcher(cx, sepstr);
|
SplitStringMatcher matcher(cx, sepstr);
|
||||||
aobj = SplitHelper(cx, linearStr, limit, matcher, type);
|
aobj = SplitHelper(cx, linearStr, limit, matcher, type);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SplitRegExpMatcher matcher(*re, cx->global()->getRegExpStatics());
|
SplitRegExpMatcher matcher(*re, cx->global()->getRegExpStatics());
|
||||||
aobj = SplitHelper(cx, linearStr, limit, matcher, type);
|
aobj = SplitHelper(cx, linearStr, limit, matcher, type);
|
||||||
@ -3302,8 +3332,14 @@ js::str_split_string(JSContext *cx, HandleTypeObject type, HandleString str, Han
|
|||||||
|
|
||||||
uint32_t limit = UINT32_MAX;
|
uint32_t limit = UINT32_MAX;
|
||||||
|
|
||||||
|
RootedObject aobj(cx);
|
||||||
|
if (linearSep->length() == 0) {
|
||||||
|
aobj = CharSplitHelper(cx, linearStr, limit);
|
||||||
|
} else {
|
||||||
SplitStringMatcher matcher(cx, linearSep);
|
SplitStringMatcher matcher(cx, linearSep);
|
||||||
ArrayObject *aobj = SplitHelper(cx, linearStr, limit, matcher, type);
|
aobj = SplitHelper(cx, linearStr, limit, matcher, type);
|
||||||
|
}
|
||||||
|
|
||||||
if (!aobj)
|
if (!aobj)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user