optimize JSON stringify. bug 561592. r=dvander
authorAndreas Gal <gal@uci.edu>
Sun, 25 Apr 2010 08:51:05 -0400
changeset 34128 e3d916b8b8d1c70cea37d00c70a155b2a5e6d1df
parent 34121 5e84745c884a59d6c4e29b4b8d0153a6c0c8366b
child 34129 00808b7f0f58632a57f14e66542d60cf00a72643
push id1284
push userbsmedberg@mozilla.com
push dateMon, 26 Apr 2010 21:33:14 +0000
reviewersdvander
bugs561592
milestone1.9.2.5pre
optimize JSON stringify. bug 561592. r=dvander
js/src/json.cpp
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -522,29 +522,25 @@ InitializeGap(JSContext *cx, jsval space
 
     return JS_TRUE;
 }
 
 JSBool
 js_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
              JSCharBuffer &cb)
 {
-    // XXX stack
-    JSObject *stack = JS_NewArrayObject(cx, 0, NULL);
-    if (!stack)
-        return JS_FALSE;
-
     StringifyContext scx(cx, cb, replacer);
     if (!InitializeGap(cx, space, scx.gap))
         return JS_FALSE;
 
     JSObject *obj = js_NewObject(cx, &js_ObjectClass, NULL, NULL);
     if (!obj)
         return JS_FALSE;
 
+    JSAutoTempValueRooter tvr(cx, obj);
     if (!obj->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.emptyAtom),
                              *vp, NULL, NULL, JSPROP_ENUMERATE)) {
         return JS_FALSE;
     }
 
     return Str(cx, ATOM_TO_JSID(cx->runtime->atomState.emptyAtom), obj, &scx, vp);
 }