Bug 653782 - Remove js_IndexToId, replace with an inline js::IndexToId. Also removes the redundant IndexToId in jsxml.cpp. r=igor
authorJeff Walden <jwalden@mit.edu>
Sat, 30 Apr 2011 03:19:26 -0400
changeset 69282 34e8a687ea80c3f5d2a679930c1d7175742073e5
parent 69281 9a5826e2fe0d8cf5bbfd79f8b3139257bb8eac76
child 69283 49f49164c1d776e07621af140d4e9b54a0f9c3bb
push idunknown
push userunknown
push dateunknown
reviewersigor
bugs653782
milestone6.0a1
Bug 653782 - Remove js_IndexToId, replace with an inline js::IndexToId. Also removes the redundant IndexToId in jsxml.cpp. r=igor
js/src/jsarray.cpp
js/src/jsarray.h
js/src/jsatominlines.h
js/src/json.cpp
js/src/jsproxy.cpp
js/src/jsxml.cpp
js/src/vm/GlobalObject.cpp
js/src/vm/GlobalObject.h
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -230,31 +230,16 @@ js_GetLengthProperty(JSContext *cx, JSOb
         *lengthp = jsuint(jsint(tvr.value().toInt32())); /* jsuint cast does ToUint32 */
         return true;
     }
 
     JS_STATIC_ASSERT(sizeof(jsuint) == sizeof(uint32_t));
     return ValueToECMAUint32(cx, tvr.value(), (uint32_t *)lengthp);
 }
 
-JSBool JS_FASTCALL
-js_IndexToId(JSContext *cx, jsuint index, jsid *idp)
-{
-    JSString *str;
-
-    if (index <= JSID_INT_MAX) {
-        *idp = INT_TO_JSID(index);
-        return JS_TRUE;
-    }
-    str = js_NumberToString(cx, index);
-    if (!str)
-        return JS_FALSE;
-    return js_ValueToStringId(cx, StringValue(str), idp);
-}
-
 static JSBool
 BigIndexToId(JSContext *cx, JSObject *obj, jsuint index, JSBool createAtom,
              jsid *idp)
 {
     jschar buf[10], *start;
     Class *clasp;
     JSAtom *atom;
     JS_STATIC_ASSERT((jsuint)-1 == 4294967295U);
@@ -2133,17 +2118,17 @@ array_push1_dense(JSContext* cx, JSObjec
 
 JS_ALWAYS_INLINE JSBool
 ArrayCompPushImpl(JSContext *cx, JSObject *obj, const Value &v)
 {
     uint32 length = obj->getArrayLength();
     if (obj->isSlowArray()) {
         /* This can happen in one evil case. See bug 630377. */
         jsid id;
-        return js_IndexToId(cx, length, &id) &&
+        return IndexToId(cx, length, &id) &&
                js_DefineProperty(cx, obj, id, &v, NULL, NULL, JSPROP_ENUMERATE);
     }
 
     JS_ASSERT(obj->isDenseArray());
     JS_ASSERT(length <= obj->getDenseArrayCapacity());
 
     if (length == obj->getDenseArrayCapacity()) {
         if (length > JS_ARGS_LENGTH_MAX) {
--- a/js/src/jsarray.h
+++ b/js/src/jsarray.h
@@ -192,19 +192,16 @@ extern JSBool
 js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
 
 extern JSBool
 js_SetLengthProperty(JSContext *cx, JSObject *obj, jsdouble length);
 
 extern JSBool
 js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
 
-extern JSBool JS_FASTCALL
-js_IndexToId(JSContext *cx, jsuint index, jsid *idp);
-
 namespace js {
 
 /*
  * This function assumes 'length' is effectively the result of calling
  * js_GetLengthProperty on aobj.
  */
 extern bool
 GetElements(JSContext *cx, JSObject *aobj, jsuint length, js::Value *vp);
--- a/js/src/jsatominlines.h
+++ b/js/src/jsatominlines.h
@@ -125,9 +125,32 @@ js_Int32ToId(JSContext* cx, int32 index,
 
     JSString* str = js_NumberToString(cx, index);
     if (!str)
         return false;
 
     return js_ValueToStringId(cx, js::StringValue(str), id);
 }
 
+namespace js {
+
+inline bool
+IndexToId(JSContext *cx, uint32 index, jsid *idp)
+{
+    if (index <= JSID_INT_MAX) {
+        *idp = INT_TO_JSID(index);
+        return true;
+    }
+
+    JSString *str = js_NumberToString(cx, index);
+    if (!str)
+        return false;
+
+    JSAtom *atom = js_AtomizeString(cx, str, 0);
+    if (!atom)
+        return false;
+    *idp = ATOM_TO_JSID(atom);
+    return true;
+}
+
+} // namespace js
+
 #endif /* jsatominlines_h___ */
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -810,17 +810,17 @@ Walk(JSContext *cx, jsid id, JSObject *h
 
         if(obj->isArray()) {
             jsuint length = 0;
             if (!js_GetLengthProperty(cx, obj, &length))
                 return false;
 
             for (jsuint i = 0; i < length; i++) {
                 jsid index;
-                if (!js_IndexToId(cx, i, &index))
+                if (!IndexToId(cx, i, &index))
                     return false;
 
                 if (!Walk(cx, index, obj, reviver, propValue.addr()))
                     return false;
 
                 if (!obj->defineProperty(cx, index, propValue.value(), NULL, NULL, JSPROP_ENUMERATE))
                     return false;
             }
@@ -1025,17 +1025,17 @@ static JSBool
 PushValue(JSContext *cx, JSONParser *jp, JSObject *parent, const Value &value)
 {
     JSBool ok;
     if (parent->isArray()) {
         jsuint len;
         ok = js_GetLengthProperty(cx, parent, &len);
         if (ok) {
             jsid index;
-            if (!js_IndexToId(cx, len, &index))
+            if (!IndexToId(cx, len, &index))
                 return JS_FALSE;
             ok = parent->defineProperty(cx, index, value, NULL, NULL, JSPROP_ENUMERATE);
         }
     } else {
         ok = JS_DefineUCProperty(cx, parent, jp->objectKey.begin(),
                                  jp->objectKey.length(), Jsvalify(value),
                                  NULL, NULL, JSPROP_ENUMERATE);
         jp->objectKey.clear();
--- a/js/src/jsproxy.cpp
+++ b/js/src/jsproxy.cpp
@@ -45,16 +45,17 @@
 #include "jsgc.h"
 #include "jsgcmark.h"
 #include "jsprvtd.h"
 #include "jsnum.h"
 #include "jsobj.h"
 #include "jsproxy.h"
 #include "jsscope.h"
 
+#include "jsatominlines.h"
 #include "jsobjinlines.h"
 
 using namespace js;
 using namespace js::gc;
 
 namespace js {
 
 static inline const Value &
@@ -434,17 +435,17 @@ ArrayToIdVector(JSContext *cx, const Val
     if (!js_GetLengthProperty(cx, obj, &length))
         return false;
 
     AutoIdRooter idr(cx);
     AutoValueRooter tvr(cx);
     for (jsuint n = 0; n < length; ++n) {
         if (!JS_CHECK_OPERATION_LIMIT(cx))
             return false;
-        if (!js_IndexToId(cx, n, idr.addr()))
+        if (!IndexToId(cx, n, idr.addr()))
             return false;
         if (!obj->getProperty(cx, idr.id(), tvr.addr()))
             return false;
         if (!ValueToId(cx, tvr.value(), idr.addr()))
             return false;
         if (!props.append(js_CheckForStringIndex(idr.id())))
             return false;
     }
--- a/js/src/jsxml.cpp
+++ b/js/src/jsxml.cpp
@@ -3494,36 +3494,16 @@ Insert(JSContext *cx, JSXML *xml, uint32
         }
     } else {
         vxml->parent = xml;
         XMLARRAY_SET_MEMBER(&xml->xml_kids, i, vxml);
     }
     return JS_TRUE;
 }
 
-static JSBool
-IndexToId(JSContext *cx, uint32 index, jsid *idp)
-{
-    JSAtom *atom;
-    JSString *str;
-
-    if (index <= JSID_INT_MAX) {
-        *idp = INT_TO_JSID(index);
-    } else {
-        str = js_NumberToString(cx, (jsdouble) index);
-        if (!str)
-            return JS_FALSE;
-        atom = js_AtomizeString(cx, str, 0);
-        if (!atom)
-            return JS_FALSE;
-        *idp = ATOM_TO_JSID(atom);
-    }
-    return JS_TRUE;
-}
-
 /* ECMA-357 9.1.1.12 XML [[Replace]]. */
 static JSBool
 Replace(JSContext *cx, JSXML *xml, uint32 i, jsval v)
 {
     uint32 n;
     JSXML *vxml, *kid;
     JSObject *vobj;
     JSString *str;