From b278f505c08024c67d1f0d8fb60661eef8f8d6fa Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Wed, 12 Dec 2012 13:21:41 +0100 Subject: [PATCH] Bug 812446 - Optimize str[double], str.char[Code]At(double). r=nbp --- js/src/ion/MCallOptimize.cpp | 6 ++++-- js/src/ion/TypeOracle.cpp | 5 +++-- js/src/jsinterpinlines.h | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/js/src/ion/MCallOptimize.cpp b/js/src/ion/MCallOptimize.cpp index d421f997980c..0c787f708bde 100644 --- a/js/src/ion/MCallOptimize.cpp +++ b/js/src/ion/MCallOptimize.cpp @@ -713,7 +713,8 @@ IonBuilder::inlineStrCharCodeAt(uint32_t argc, bool constructing) return InliningStatus_NotInlined; if (getInlineArgType(argc, 0) != MIRType_String) return InliningStatus_NotInlined; - if (getInlineArgType(argc, 1) != MIRType_Int32) + MIRType argType = getInlineArgType(argc, 1); + if (argType != MIRType_Int32 && argType != MIRType_Double) return InliningStatus_NotInlined; MDefinitionVector argv; @@ -768,7 +769,8 @@ IonBuilder::inlineStrCharAt(uint32_t argc, bool constructing) return InliningStatus_NotInlined; if (getInlineArgType(argc, 0) != MIRType_String) return InliningStatus_NotInlined; - if (getInlineArgType(argc, 1) != MIRType_Int32) + MIRType argType = getInlineArgType(argc, 1); + if (argType != MIRType_Int32 && argType != MIRType_Double) return InliningStatus_NotInlined; MDefinitionVector argv; diff --git a/js/src/ion/TypeOracle.cpp b/js/src/ion/TypeOracle.cpp index 0caabcb137b9..97f28b367d61 100644 --- a/js/src/ion/TypeOracle.cpp +++ b/js/src/ion/TypeOracle.cpp @@ -348,14 +348,15 @@ TypeInferenceOracle::elementReadIsTypedArray(JSScript *script, jsbytecode *pc, i bool TypeInferenceOracle::elementReadIsString(JSScript *script, jsbytecode *pc) { - // Check for string[int32]. + // Check for string[index]. StackTypeSet *value = script->analysis()->poppedTypes(pc, 1); StackTypeSet *id = script->analysis()->poppedTypes(pc, 0); if (value->getKnownTypeTag() != JSVAL_TYPE_STRING) return false; - if (id->getKnownTypeTag() != JSVAL_TYPE_INT32) + JSValueType idType = id->getKnownTypeTag(); + if (idType != JSVAL_TYPE_INT32 && idType != JSVAL_TYPE_DOUBLE) return false; // This function is used for jsop_getelem_string which should return diff --git a/js/src/jsinterpinlines.h b/js/src/jsinterpinlines.h index bcca83addae5..be4e92fca0c1 100644 --- a/js/src/jsinterpinlines.h +++ b/js/src/jsinterpinlines.h @@ -790,11 +790,11 @@ GetElementOperation(JSContext *cx, JSOp op, HandleValue lref, HandleValue rref, AssertCanGC(); JS_ASSERT(op == JSOP_GETELEM || op == JSOP_CALLELEM); - if (lref.isString() && rref.isInt32()) { + uint32_t index; + if (lref.isString() && IsDefinitelyIndex(rref, &index)) { JSString *str = lref.toString(); - int32_t i = rref.toInt32(); - if (size_t(i) < str->length()) { - str = cx->runtime->staticStrings.getUnitStringForElement(cx, str, size_t(i)); + if (index < str->length()) { + str = cx->runtime->staticStrings.getUnitStringForElement(cx, str, index); if (!str) return false; res.setString(str);