Bug 715561 - Tidy up js_XDRStaticBlockObject (r=jorendorff)
authorLuke Wagner <luke@mozilla.com>
Mon, 09 Jan 2012 10:23:38 -0800
changeset 85593 53d56e848d1a0bb3a4fbf828744651a46bf816a7
parent 85592 c3956cae4197b331e8ef854d4a96d0bdd47e1a95
child 85594 8c24766efc04643ab9510f229a3edd171ea84a2e
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs715561
milestone12.0a1
Bug 715561 - Tidy up js_XDRStaticBlockObject (r=jorendorff)
js/src/vm/ScopeObject.cpp
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -611,117 +611,102 @@ FindObjectIndex(JSObjectArray *array, JS
     }
 
     return NO_PARENT_INDEX;
 }
 
 bool
 js_XDRStaticBlockObject(JSXDRState *xdr, StaticBlockObject **objp)
 {
-    JSContext *cx;
-    uint32_t parentId;
-    StaticBlockObject *obj, *parent;
-    uintN depth, count;
-    uint32_t depthAndCount;
-    const Shape *shape;
+    JSContext *cx = xdr->cx;
 
-    cx = xdr->cx;
-#ifdef __GNUC__
-    obj = NULL;         /* quell GCC overwarning */
-#endif
-
+    StaticBlockObject *obj = NULL;
+    uint32_t parentId = 0;
+    uint32_t count = 0;
+    uint32_t depthAndCount = 0;
     if (xdr->mode == JSXDR_ENCODE) {
         obj = *objp;
-        parent = obj->enclosingBlock();
         parentId = JSScript::isValidOffset(xdr->script->objectsOffset)
-                   ? FindObjectIndex(xdr->script->objects(), parent)
+                   ? FindObjectIndex(xdr->script->objects(), obj->enclosingBlock())
                    : NO_PARENT_INDEX;
-        depth = uint16_t(obj->stackDepth());
-        count = uint16_t(obj->slotCount());
-        depthAndCount = uint32_t(depth << 16) | count;
+        uint32_t depth = obj->stackDepth();
+        JS_ASSERT(depth <= UINT16_MAX);
+        count = obj->slotCount();
+        JS_ASSERT(count <= UINT16_MAX);
+        depthAndCount = (depth << 16) | uint16_t(count);
     }
-#ifdef __GNUC__ /* suppress bogus gcc warnings */
-    else count = 0;
-#endif
 
     /* First, XDR the parent atomid. */
     if (!JS_XDRUint32(xdr, &parentId))
-        return JS_FALSE;
+        return false;
 
     if (xdr->mode == JSXDR_DECODE) {
         obj = StaticBlockObject::create(cx);
         if (!obj)
-            return JS_FALSE;
+            return false;
         *objp = obj;
 
         /*
          * If there's a parent id, then get the parent out of our script's
          * object array. We know that we XDR block object in outer-to-inner
          * order, which means that getting the parent now will work.
          */
-        if (parentId == NO_PARENT_INDEX)
-            parent = NULL;
-        else
-            parent = &xdr->script->getObject(parentId)->asStaticBlock();
-        obj->setEnclosingBlock(parent);
+        obj->setEnclosingBlock(parentId == NO_PARENT_INDEX
+                               ? NULL
+                               : &xdr->script->getObject(parentId)->asStaticBlock());
     }
 
     AutoObjectRooter tvr(cx, obj);
 
     if (!JS_XDRUint32(xdr, &depthAndCount))
         return false;
 
     if (xdr->mode == JSXDR_DECODE) {
-        depth = uint16_t(depthAndCount >> 16);
+        uint32_t depth = uint16_t(depthAndCount >> 16);
         count = uint16_t(depthAndCount);
         obj->setStackDepth(depth);
 
         /*
          * XDR the block object's properties. We know that there are 'count'
          * properties to XDR, stored as id/shortid pairs.
          */
         for (uintN i = 0; i < count; i++) {
+            /* XDR the real id. */
             JSAtom *atom;
-
-            /* XDR the real id. */
             if (!js_XDRAtom(xdr, &atom))
                 return false;
 
             bool redeclared;
             if (!obj->addVar(cx, ATOM_TO_JSID(atom), i, &redeclared)) {
                 JS_ASSERT(!redeclared);
                 return false;
             }
         }
     } else {
         AutoShapeVector shapes(cx);
         shapes.growBy(count);
 
         for (Shape::Range r(obj->lastProperty()); !r.empty(); r.popFront()) {
-            shape = &r.front();
+            const Shape *shape = &r.front();
             shapes[shape->shortid()] = shape;
         }
 
         /*
          * XDR the block object's properties. We know that there are 'count'
          * properties to XDR, stored as id/shortid pairs.
          */
         for (uintN i = 0; i < count; i++) {
-            shape = shapes[i];
+            const Shape *shape = shapes[i];
             JS_ASSERT(shape->getter() == block_getProperty);
+            JS_ASSERT(uintN(shape->shortid()) == i);
 
             jsid propid = shape->propid();
             JS_ASSERT(JSID_IS_ATOM(propid));
             JSAtom *atom = JSID_TO_ATOM(propid);
 
-#ifdef DEBUG
-            uint16_t shortid = uint16_t(shape->shortid());
-            JS_ASSERT(shortid == i);
-#endif
-
             /* XDR the real id. */
             if (!js_XDRAtom(xdr, &atom))
                 return false;
         }
     }
     return true;
 }