Bug 836949 - Remove InternNonIntElementId/FetchElementId. r=jwalden
authorTom Schuster <evilpies@gmail.com>
Tue, 09 Apr 2013 13:33:32 +0200
changeset 139091 53273047c43e9ac0a3d3fd00ab98b966754b1501
parent 139090 3fd383ca51c812e99a2c8c1fdf692a57d9d336a4
child 139092 471f0b0a58e11e7628f8b3c6cd3f9fe5644f30c4
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs836949
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 836949 - Remove InternNonIntElementId/FetchElementId. r=jwalden
js/src/frontend/BytecodeEmitter.cpp
js/src/ion/BaselineIC.cpp
js/src/ion/IonCaches.cpp
js/src/ion/VMFunctions.cpp
js/src/jsatom.cpp
js/src/jsatom.h
js/src/jsatominlines.h
js/src/jsinterp.cpp
js/src/jsinterpinlines.h
js/src/methodjit/PolyIC.cpp
js/src/methodjit/StubCalls.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -3451,37 +3451,52 @@ ParseNode::getConstantValue(JSContext *c
       case PNK_OBJECT: {
         JS_ASSERT(isOp(JSOP_NEWINIT) && !(pn_xflags & PNX_NONCONST));
 
         gc::AllocKind kind = GuessObjectGCKind(pn_count);
         RootedObject obj(cx, NewBuiltinClassInstance(cx, &ObjectClass, kind, MaybeSingletonObject));
         if (!obj)
             return false;
 
+        RootedValue value(cx), idvalue(cx);
         for (ParseNode *pn = pn_head; pn; pn = pn->pn_next) {
-            RootedValue value(cx);
             if (!pn->pn_right->getConstantValue(cx, strictChecks, &value))
                 return false;
 
             ParseNode *pnid = pn->pn_left;
             if (pnid->isKind(PNK_NUMBER)) {
-                Value idvalue = NumberValue(pnid->pn_dval);
-                RootedId id(cx);
-                if (idvalue.isInt32() && INT_FITS_IN_JSID(idvalue.toInt32()))
-                    id = INT_TO_JSID(idvalue.toInt32());
-                else if (!InternNonIntElementId<CanGC>(cx, obj, idvalue, &id))
-                    return false;
-                if (!JSObject::defineGeneric(cx, obj, id, value, NULL, NULL, JSPROP_ENUMERATE))
-                    return false;
+                idvalue = NumberValue(pnid->pn_dval);
             } else {
                 JS_ASSERT(pnid->isKind(PNK_NAME) || pnid->isKind(PNK_STRING));
                 JS_ASSERT(pnid->pn_atom != cx->names().proto);
-                RootedId id(cx, AtomToId(pnid->pn_atom));
-                if (!DefineNativeProperty(cx, obj, id, value, NULL, NULL,
-                                          JSPROP_ENUMERATE, 0, 0)) {
+                idvalue = StringValue(pnid->pn_atom);
+            }
+
+            uint32_t index;
+            if (IsDefinitelyIndex(idvalue, &index)) {
+                if (!JSObject::defineElement(cx, obj, index, value, NULL, NULL,
+                                             JSPROP_ENUMERATE))
+                {
+                    return false;
+                }
+
+                continue;
+            }
+
+            JSAtom *name = ToAtom<CanGC>(cx, idvalue);
+            if (!name)
+                return false;
+
+            if (name->isIndex(&index)) {
+                if (!JSObject::defineElement(cx, obj, index, value, NULL, NULL, JSPROP_ENUMERATE))
+                    return false;
+            } else {
+                if (!JSObject::defineProperty(cx, obj, name->asPropertyName(), value, NULL, NULL,
+                                              JSPROP_ENUMERATE))
+                {
                     return false;
                 }
             }
         }
 
         types::FixObjectType(cx, obj);
         vp.setObject(*obj);
         return true;
--- a/js/src/ion/BaselineIC.cpp
+++ b/js/src/ion/BaselineIC.cpp
@@ -3213,18 +3213,17 @@ TypedArrayGetElemStubExists(ICGetElem_Fa
 }
 
 
 static bool TryAttachNativeGetElemStub(JSContext *cx, HandleScript script,
                                        ICGetElem_Fallback *stub, HandleObject obj,
                                        HandleValue key)
 {
     RootedId id(cx);
-    RootedValue idval(cx);
-    if (!FetchElementId(cx, obj, key, &id, &idval))
+    if (!ValueToId<CanGC>(cx, key, &id))
         return false;
 
     uint32_t dummy;
     if (!JSID_IS_ATOM(id) || JSID_TO_ATOM(id)->isIndex(&dummy))
         return true;
 
     RootedPropertyName propName(cx, JSID_TO_ATOM(id)->asPropertyName());
 
@@ -3754,18 +3753,17 @@ DoSetElemFallback(JSContext *cx, Baselin
     uint32_t oldCapacity = 0;
     uint32_t oldInitLength = 0;
     if (obj->isNative() && index.isInt32() && index.toInt32() >= 0) {
         oldCapacity = obj->getDenseCapacity();
         oldInitLength = obj->getDenseInitializedLength();
     }
 
     if (op == JSOP_INITELEM) {
-        RootedValue nindex(cx, index);
-        if (!InitElemOperation(cx, obj, &nindex, rhs))
+        if (!InitElemOperation(cx, obj, index, rhs))
             return false;
     } else if (op == JSOP_INITELEM_ARRAY) {
         JS_ASSERT(uint32_t(index.toInt32()) == GET_UINT24(pc));
         if (!InitArrayElemOperation(cx, pc, obj, index.toInt32(), rhs))
             return false;
     } else {
         if (!SetObjectElement(cx, obj, index, rhs, script->strict, script, pc))
             return false;
--- a/js/src/ion/IonCaches.cpp
+++ b/js/src/ion/IonCaches.cpp
@@ -1862,17 +1862,17 @@ GetElementIC::update(JSContext *cx, size
         return true;
     }
 
     // Override the return value if we are invalidated (bug 728188).
     AutoFlushCache afc ("GetElementCache");
     AutoDetectInvalidation adi(cx, res.address(), ion);
 
     RootedId id(cx);
-    if (!FetchElementId(cx, obj, idval, &id, res))
+    if (!ValueToId<CanGC>(cx, idval, &id))
         return false;
 
     bool attachedStub = false;
     if (cache.canAttachStub()) {
         if (obj->isNative() && cache.monitoredResult()) {
             uint32_t dummy;
             if (idval.isString() && JSID_IS_ATOM(id) && !JSID_TO_ATOM(id)->isIndex(&dummy)) {
                 RootedPropertyName name(cx, JSID_TO_ATOM(id)->asPropertyName());
--- a/js/src/ion/VMFunctions.cpp
+++ b/js/src/ion/VMFunctions.cpp
@@ -490,19 +490,18 @@ SPSExit(JSContext *cx, HandleScript scri
 {
     cx->runtime->spsProfiler.exit(cx, script, script->function());
     return true;
 }
 
 bool
 OperatorIn(JSContext *cx, HandleValue key, HandleObject obj, JSBool *out)
 {
-    RootedValue dummy(cx); // Disregards atomization changes: no way to propagate.
     RootedId id(cx);
-    if (!FetchElementId(cx, obj, key, &id, &dummy))
+    if (!ValueToId<CanGC>(cx, key, &id))
         return false;
 
     RootedObject obj2(cx);
     RootedShape prop(cx);
     if (!JSObject::lookupGeneric(cx, obj, id, &obj2, &prop))
         return false;
 
     *out = !!prop;
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -433,39 +433,16 @@ js::IndexToIdSlow(JSContext *cx, uint32_
 }
 
 template bool
 js::IndexToIdSlow<CanGC>(JSContext *cx, uint32_t index, MutableHandleId idp);
 
 template bool
 js::IndexToIdSlow<NoGC>(JSContext *cx, uint32_t index, FakeMutableHandle<jsid> idp);
 
-template <AllowGC allowGC>
-bool
-js::InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
-                          typename MaybeRooted<jsid, allowGC>::MutableHandleType idp,
-                          typename MaybeRooted<Value, allowGC>::MutableHandleType vp)
-{
-    JSAtom *atom = ToAtom<allowGC>(cx, idval);
-    if (!atom)
-        return false;
-
-    idp.set(AtomToId(atom));
-    vp.setString(atom);
-    return true;
-}
-
-template bool
-js::InternNonIntElementId<CanGC>(JSContext *cx, JSObject *obj, const Value &idval,
-                                 MutableHandleId idp, MutableHandleValue vp);
-
-template bool
-js::InternNonIntElementId<NoGC>(JSContext *cx, JSObject *obj, const Value &idval,
-                                FakeMutableHandle<jsid> idp, FakeMutableHandle<Value> vp);
-
 template<XDRMode mode>
 bool
 js::XDRAtom(XDRState<mode> *xdr, MutableHandleAtom atomp)
 {
     if (mode == XDR_ENCODE) {
         uint32_t nchars = atomp->length();
         if (!xdr->codeUint32(&nchars))
             return false;
--- a/js/src/jsatom.h
+++ b/js/src/jsatom.h
@@ -234,30 +234,15 @@ AtomizeChars(JSContext *cx, const jschar
 template <AllowGC allowGC>
 extern RawAtom
 AtomizeString(JSContext *cx, JSString *str, js::InternBehavior ib = js::DoNotInternAtom);
 
 template <AllowGC allowGC>
 inline JSAtom *
 ToAtom(JSContext *cx, const js::Value &v);
 
-template <AllowGC allowGC>
-bool
-InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
-                      typename MaybeRooted<jsid, allowGC>::MutableHandleType idp,
-                      typename MaybeRooted<Value, allowGC>::MutableHandleType vp);
-
-template <AllowGC allowGC>
-inline bool
-InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
-                      typename MaybeRooted<jsid, allowGC>::MutableHandleType idp)
-{
-    typename MaybeRooted<Value, allowGC>::RootType dummy(cx);
-    return InternNonIntElementId<allowGC>(cx, obj, idval, idp, &dummy);
-}
-
 template<XDRMode mode>
 bool
 XDRAtom(XDRState<mode> *xdr, js::MutableHandleAtom atomp);
 
 } /* namespace js */
 
 #endif /* jsatom_h___ */
--- a/js/src/jsatominlines.h
+++ b/js/src/jsatominlines.h
@@ -24,16 +24,28 @@ js::AtomStateEntry::asPtr() const
     JS_ASSERT(bits != 0);
     JSAtom *atom = reinterpret_cast<JSAtom *>(bits & NO_TAG_MASK);
     JSString::readBarrier(atom);
     return atom;
 }
 
 namespace js {
 
+inline jsid
+AtomToId(JSAtom *atom)
+{
+    JS_STATIC_ASSERT(JSID_INT_MIN == 0);
+
+    uint32_t index;
+    if (atom->isIndex(&index) && index <= JSID_INT_MAX)
+        return INT_TO_JSID(int32_t(index));
+
+    return JSID_FROM_BITS(size_t(atom));
+}
+
 template <AllowGC allowGC>
 inline JSAtom *
 ToAtom(JSContext *cx, const js::Value &v)
 {
     if (!v.isString()) {
         JSString *str = js::ToStringSlow<allowGC>(cx, v);
         if (!str)
             return NULL;
@@ -55,17 +67,22 @@ ValueToId(JSContext* cx, JSObject *obj, 
           typename MaybeRooted<jsid, allowGC>::MutableHandleType idp)
 {
     int32_t i;
     if (ValueFitsInInt32(v, &i) && INT_FITS_IN_JSID(i)) {
         idp.set(INT_TO_JSID(i));
         return true;
     }
 
-    return InternNonIntElementId<allowGC>(cx, obj, v, idp);
+    JSAtom *atom = ToAtom<allowGC>(cx, v);
+    if (!atom)
+        return false;
+
+    idp.set(AtomToId(atom));
+    return true;
 }
 
 template <AllowGC allowGC>
 inline bool
 ValueToId(JSContext* cx, const Value &v,
           typename MaybeRooted<jsid, allowGC>::MutableHandleType idp)
 {
     return ValueToId<allowGC>(cx, NULL, v, idp);
@@ -124,28 +141,16 @@ IndexToIdNoGC(JSContext *cx, uint32_t in
     if (index <= JSID_INT_MAX) {
         *idp = INT_TO_JSID(index);
         return true;
     }
 
     return IndexToIdSlow<NoGC>(cx, index, idp);
 }
 
-inline jsid
-AtomToId(JSAtom *atom)
-{
-    JS_STATIC_ASSERT(JSID_INT_MIN == 0);
-
-    uint32_t index;
-    if (atom->isIndex(&index) && index <= JSID_INT_MAX)
-        return INT_TO_JSID((int32_t) index);
-
-    return JSID_FROM_BITS((size_t)atom);
-}
-
 static JS_ALWAYS_INLINE JSFlatString *
 IdToString(JSContext *cx, jsid id)
 {
     if (JSID_IS_STRING(id))
         return JSID_TO_ATOM(id);
 
     if (JS_LIKELY(JSID_IS_INT(id)))
         return Int32ToString<CanGC>(cx, JSID_TO_INT(id));
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -2987,17 +2987,17 @@ BEGIN_CASE(JSOP_INITPROP)
     regs.sp--;
 }
 END_CASE(JSOP_INITPROP);
 
 BEGIN_CASE(JSOP_INITELEM)
 {
     JS_ASSERT(regs.stackDepth() >= 3);
     HandleValue val = HandleValue::fromMarkedLocation(&regs.sp[-1]);
-    MutableHandleValue id = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
+    HandleValue id = HandleValue::fromMarkedLocation(&regs.sp[-2]);
 
     RootedObject &obj = rootObject0;
     obj = &regs.sp[-3].toObject();
 
     if (!InitElemOperation(cx, obj, id, val))
         goto error;
 
     regs.sp -= 2;
@@ -3677,30 +3677,28 @@ js::CallElement(JSContext *cx, MutableHa
     return GetElementOperation(cx, JSOP_CALLELEM, lref, rref, res);
 }
 
 bool
 js::SetObjectElement(JSContext *cx, HandleObject obj, HandleValue index, HandleValue value,
                      JSBool strict)
 {
     RootedId id(cx);
-    RootedValue indexval(cx, index);
-    if (!FetchElementId(cx, obj, indexval, &id, &indexval))
+    if (!ValueToId<CanGC>(cx, index, &id))
         return false;
     return SetObjectElementOperation(cx, obj, id, value, strict);
 }
 
 bool
 js::SetObjectElement(JSContext *cx, HandleObject obj, HandleValue index, HandleValue value,
                      JSBool strict, HandleScript script, jsbytecode *pc)
 {
     JS_ASSERT(pc);
     RootedId id(cx);
-    RootedValue indexval(cx, index);
-    if (!FetchElementId(cx, obj, indexval, &id, &indexval))
+    if (!ValueToId<CanGC>(cx, index, &id))
         return false;
     return SetObjectElementOperation(cx, obj, id, value, strict, script, pc);
 }
 
 bool
 js::AddValues(JSContext *cx, HandleScript script, jsbytecode *pc,
               MutableHandleValue lhs, MutableHandleValue rhs,
               Value *res)
--- a/js/src/jsinterpinlines.h
+++ b/js/src/jsinterpinlines.h
@@ -706,45 +706,34 @@ NegOperation(JSContext *cx, HandleScript
         d = -d;
         if (!res.setNumber(d) && !val.isDouble())
             types::TypeScript::MonitorOverflow(cx, script, pc);
     }
 
     return true;
 }
 
-static inline bool
-FetchElementId(JSContext *cx, JSObject *obj, const Value &idval, MutableHandleId idp,
-               MutableHandleValue vp)
-{
-    int32_t i_;
-    if (ValueFitsInInt32(idval, &i_) && INT_FITS_IN_JSID(i_)) {
-        idp.set(INT_TO_JSID(i_));
-        return true;
-    }
-    return !!InternNonIntElementId<CanGC>(cx, obj, idval, idp, vp);
-}
-
 static JS_ALWAYS_INLINE bool
 ToIdOperation(JSContext *cx, HandleScript script, jsbytecode *pc, HandleValue objval,
               HandleValue idval, MutableHandleValue res)
 {
     if (idval.isInt32()) {
         res.set(idval);
         return true;
     }
 
     JSObject *obj = ToObjectFromStack(cx, objval);
     if (!obj)
         return false;
 
-    RootedId dummy(cx);
-    if (!InternNonIntElementId<CanGC>(cx, obj, idval, &dummy, res))
+    RootedId id(cx);
+    if (!ValueToId<CanGC>(cx, idval, &id))
         return false;
 
+    res.set(IdToValue(id));
     if (!res.isInt32())
         types::TypeScript::MonitorUnknown(cx, script, pc);
     return true;
 }
 
 static JS_ALWAYS_INLINE bool
 GetObjectElementOperation(JSContext *cx, JSOp op, JSObject *objArg, bool wasObject,
                           HandleValue rref, MutableHandleValue res)
@@ -930,22 +919,22 @@ SetObjectElementOperation(JSContext *cx,
 static JS_ALWAYS_INLINE JSString *
 TypeOfOperation(JSContext *cx, HandleValue v)
 {
     JSType type = JS_TypeOfValue(cx, v);
     return TypeName(type, cx);
 }
 
 static JS_ALWAYS_INLINE bool
-InitElemOperation(JSContext *cx, HandleObject obj, MutableHandleValue idval, HandleValue val)
+InitElemOperation(JSContext *cx, HandleObject obj, HandleValue idval, HandleValue val)
 {
     JS_ASSERT(!val.isMagic(JS_ELEMENTS_HOLE));
 
     RootedId id(cx);
-    if (!FetchElementId(cx, obj, idval, &id, idval))
+    if (!ValueToId<CanGC>(cx, idval, &id))
         return false;
 
     return JSObject::defineGeneric(cx, obj, id, val, NULL, NULL, JSPROP_ENUMERATE);
 }
 
 static JS_ALWAYS_INLINE bool
 InitArrayElemOperation(JSContext *cx, jsbytecode *pc, HandleObject obj, uint32_t index, HandleValue val)
 {
--- a/js/src/methodjit/PolyIC.cpp
+++ b/js/src/methodjit/PolyIC.cpp
@@ -2610,23 +2610,19 @@ ic::GetElement(VMFrame &f, ic::GetElemen
 
     RecompilationMonitor monitor(cx);
 
     RootedValue objval(f.cx, f.regs.sp[-2]);
     RootedObject obj(cx, ToObjectFromStack(cx, objval));
     if (!obj)
         THROW();
 
-    Rooted<jsid> id(cx);
-    if (idval.isInt32() && INT_FITS_IN_JSID(idval.toInt32())) {
-        id = INT_TO_JSID(idval.toInt32());
-    } else {
-        if (!InternNonIntElementId<CanGC>(cx, obj, idval, &id))
+    RootedId id(cx);
+    if (!ValueToId<CanGC>(cx, idval, &id))
             THROW();
-    }
 
     MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&f.regs.sp[-2]);
 
     if (!monitor.recompiled() && ic->shouldUpdate(f)) {
 #ifdef DEBUG
         f.regs.sp[-2] = MagicValue(JS_GENERIC_MAGIC);
 #endif
         LookupStatus status = ic->update(f, obj, idval, id, res);
--- a/js/src/methodjit/StubCalls.cpp
+++ b/js/src/methodjit/StubCalls.cpp
@@ -131,27 +131,23 @@ stubs::SetElem(VMFrame &f)
 {
     JSContext *cx = f.cx;
     FrameRegs &regs = f.regs;
 
     HandleValue objval = HandleValue::fromMarkedLocation(&regs.sp[-3]);
     Value &idval  = regs.sp[-2];
     RootedValue rval(cx, regs.sp[-1]);
 
-    RootedId id(cx);
-
     RootedObject obj(cx, ToObjectFromStack(cx, objval));
     if (!obj)
         THROW();
 
-    if (!FetchElementId(f.cx, obj, idval, &id,
-                        MutableHandleValue::fromMarkedLocation(&regs.sp[-2])))
-    {
+    RootedId id(f.cx);
+    if (!ValueToId<CanGC>(f.cx, idval, &id))
         THROW();
-    }
 
     TypeScript::MonitorAssign(cx, obj, id);
 
     if (obj->isArray() && JSID_IS_INT(id)) {
         uint32_t length = obj->getDenseInitializedLength();
         int32_t i = JSID_TO_INT(id);
         if ((uint32_t)i >= length) {
             if (f.script()->hasAnalysis())
@@ -178,19 +174,20 @@ stubs::ToId(VMFrame &f)
     HandleValue objval = HandleValue::fromMarkedLocation(&f.regs.sp[-2]);
     MutableHandleValue idval = MutableHandleValue::fromMarkedLocation(&f.regs.sp[-1]);
 
     JSObject *obj = ToObjectFromStack(f.cx, objval);
     if (!obj)
         THROW();
 
     RootedId id(f.cx);
-    if (!FetchElementId(f.cx, obj, idval, &id, idval))
+    if (!ValueToId<CanGC>(f.cx, idval, &id))
         THROW();
 
+    idval.set(IdToValue(id));
     if (!idval.isInt32()) {
         RootedScript fscript(f.cx, f.script());
         TypeScript::MonitorUnknown(f.cx, fscript, f.pc());
     }
 }
 
 void JS_FASTCALL
 stubs::ImplicitThis(VMFrame &f, PropertyName *name_)
@@ -1445,21 +1442,18 @@ stubs::In(VMFrame &f)
     if (!rref.isObject()) {
         RootedValue val(cx, rref);
         js_ReportValueError(cx, JSMSG_IN_NOT_OBJECT, -1, val, NullPtr());
         THROWV(JS_FALSE);
     }
 
     RootedObject obj(cx, &rref.toObject());
     RootedId id(cx);
-    if (!FetchElementId(f.cx, obj, f.regs.sp[-2], &id,
-                        MutableHandleValue::fromMarkedLocation(&f.regs.sp[-2])))
-    {
+    if (!ValueToId<CanGC>(f.cx, f.regs.sp[-2], &id))
         THROWV(JS_FALSE);
-    }
 
     RootedObject obj2(cx);
     RootedShape prop(cx);
     if (!JSObject::lookupGeneric(cx, obj, id, &obj2, &prop))
         THROWV(JS_FALSE);
 
     return !!prop;
 }