From 3f3dd1a810b166303c3e2aaba168b74f3e4e9691 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Tue, 11 Dec 2007 08:36:29 +0000 Subject: [PATCH] bug 407428. stack allocate small strings in js_XDRStringAtom instead of instead of using the tempPool arena to allocate them. r=brendan,igor git-svn-id: svn://10.0.0.236/trunk@240793 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/jsxdrapi.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mozilla/js/src/jsxdrapi.c b/mozilla/js/src/jsxdrapi.c index 0b9146f67e6..ad1aef11646 100644 --- a/mozilla/js/src/jsxdrapi.c +++ b/mozilla/js/src/jsxdrapi.c @@ -644,8 +644,8 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp) uint32 nchars; JSAtom *atom; JSContext *cx; - void *mark; jschar *chars; + jschar stackChars[256]; if (xdr->mode == JSXDR_ENCODE) { JS_ASSERT(ATOM_IS_STRING(*atomp)); @@ -661,14 +661,23 @@ js_XDRStringAtom(JSXDRState *xdr, JSAtom **atomp) return JS_FALSE; atom = NULL; cx = xdr->cx; - mark = JS_ARENA_MARK(&cx->tempPool); - JS_ARENA_ALLOCATE_CAST(chars, jschar *, &cx->tempPool, - nchars * sizeof(jschar)); - if (!chars) - js_ReportOutOfScriptQuota(cx); - else if (XDRChars(xdr, chars, nchars)) + if (nchars <= JS_ARRAY_LENGTH(stackChars)) { + chars = stackChars; + } 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) + return JS_FALSE; + } + + if (XDRChars(xdr, chars, nchars)) atom = js_AtomizeChars(cx, chars, nchars, 0); - JS_ARENA_RELEASE(&cx->tempPool, mark); + if (chars != stackChars) + JS_free(cx, chars); + if (!atom) return JS_FALSE; *atomp = atom;