Special case object lookup lambda in String.replace, bug 605317. r=jorendorff

This commit is contained in:
Brian Hackett
2010-10-28 14:33:32 -07:00
parent ca48e19fec
commit b39e767168
6 changed files with 180 additions and 47 deletions

View File

@@ -463,42 +463,13 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
if (str->isAtomized())
return STRING_TO_ATOM(str);
size_t length = str->length();
if (length == 1) {
jschar c = str->chars()[0];
if (c < UNIT_STRING_LIMIT)
return STRING_TO_ATOM(JSString::unitString(c));
}
const jschar *chars;
size_t length;
str->getCharsAndLength(chars, length);
if (length == 2) {
jschar *chars = str->chars();
if (JSString::fitsInSmallChar(chars[0]) &&
JSString::fitsInSmallChar(chars[1])) {
return STRING_TO_ATOM(JSString::length2String(chars[0], chars[1]));
}
}
/*
* Here we know that JSString::intStringTable covers only 256 (or at least
* not 1000 or more) chars. We rely on order here to resolve the unit vs.
* int string/length-2 string atom identity issue by giving priority to unit
* strings for "0" through "9" and length-2 strings for "10" through "99".
*/
JS_STATIC_ASSERT(INT_STRING_LIMIT <= 999);
if (length == 3) {
const jschar *chars = str->chars();
if ('1' <= chars[0] && chars[0] <= '9' &&
'0' <= chars[1] && chars[1] <= '9' &&
'0' <= chars[2] && chars[2] <= '9') {
jsint i = (chars[0] - '0') * 100 +
(chars[1] - '0') * 10 +
(chars[2] - '0');
if (jsuint(i) < INT_STRING_LIMIT)
return STRING_TO_ATOM(JSString::intString(i));
}
}
JSString *staticStr = JSString::lookupStaticString(chars, length);
if (staticStr)
return STRING_TO_ATOM(staticStr);
JSAtomState *state = &cx->runtime->atomState;
AtomSet &atoms = state->atoms;