зеркало из https://github.com/mozilla/pjs.git
bug 407428. stack allocate small strings in js_XDRStringAtom instead of instead of using the tempPool arena to allocate them. r=brendan,igor
This commit is contained in:
Родитель
8400923b32
Коммит
36d7c1065d
|
@ -644,8 +644,8 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp)
|
||||||
uint32 nchars;
|
uint32 nchars;
|
||||||
JSAtom *atom;
|
JSAtom *atom;
|
||||||
JSContext *cx;
|
JSContext *cx;
|
||||||
void *mark;
|
|
||||||
jschar *chars;
|
jschar *chars;
|
||||||
|
jschar stackChars[256];
|
||||||
|
|
||||||
if (xdr->mode == JSXDR_ENCODE) {
|
if (xdr->mode == JSXDR_ENCODE) {
|
||||||
JS_ASSERT(ATOM_IS_STRING(*atomp));
|
JS_ASSERT(ATOM_IS_STRING(*atomp));
|
||||||
|
@ -661,14 +661,23 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp)
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
atom = NULL;
|
atom = NULL;
|
||||||
cx = xdr->cx;
|
cx = xdr->cx;
|
||||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
if (nchars <= JS_ARRAY_LENGTH(stackChars)) {
|
||||||
JS_ARENA_ALLOCATE_CAST(chars, jschar *, &cx->tempPool,
|
chars = stackChars;
|
||||||
nchars * sizeof(jschar));
|
} else {
|
||||||
|
/*
|
||||||
|
* This is very uncommon. Don't use the tempPool arena for this as
|
||||||
|
* most allocations here will be bigger than tempPool's arenasize.
|
||||||
|
*/
|
||||||
|
chars = (jschar *) JS_malloc(cx, nchars * sizeof(jschar));
|
||||||
if (!chars)
|
if (!chars)
|
||||||
js_ReportOutOfScriptQuota(cx);
|
return JS_FALSE;
|
||||||
else if (XDRChars(xdr, chars, nchars))
|
}
|
||||||
|
|
||||||
|
if (XDRChars(xdr, chars, nchars))
|
||||||
atom = js_AtomizeChars(cx, chars, nchars, 0);
|
atom = js_AtomizeChars(cx, chars, nchars, 0);
|
||||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
if (chars != stackChars)
|
||||||
|
JS_free(cx, chars);
|
||||||
|
|
||||||
if (!atom)
|
if (!atom)
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
*atomp = atom;
|
*atomp = atom;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче