Ignore:
Timestamp:
Jul 28, 2011, 5:43:15 PM (14 years ago)
Author:
[email protected]
Message:

Source/JavaScriptCore: *_list instructions are only used in one place, where the code is wrong.
https://bugs.webkit.org/show_bug.cgi?id=65348

Patch by Oliver Hunt <[email protected]> on 2011-07-28
Reviewed by Darin Adler.

Simply remove the instructions and all users. Speeds up the interpreter
slightly due to code motion, but otherwise has no effect (because none
of the _list instructions are ever used).

  • bytecode/CodeBlock.cpp:

(JSC::isPropertyAccess):
(JSC::CodeBlock::dump):
(JSC::CodeBlock::visitStructures):

  • bytecode/Instruction.h:
  • bytecode/Opcode.h:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • jit/JIT.cpp:

(JSC::JIT::privateCompileMainPass):

LayoutTests: https://bugs.webkit.org/show_bug.cgi?id=65325
Performance tweak to parseInt

Reviewed by Oliver Hunt.

  • fast/js/parseInt-expected.txt: Added.
  • fast/js/parseInt.html: Added.
  • fast/js/script-tests/parseInt.js: Added.
    • Added test cases.
  • sputnik/Conformance/15_Native_Objects/15.1_The_Global_Object/15.1.2/15.1.2.2_parseInt/S15.1.2.2_A1_T2-expected.txt:
    • Fixed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r91938 r91966  
    461461{
    462462    JSValue value = exec->argument(0);
    463 
    464     // Optimized case: If the argument is a positive number in the integer
    465     // range, and the exponent is 10, then parseInt is equivalent to floor.
     463    JSValue radixValue = exec->argument(1);
     464
     465    // Optimized handling for numbers:
     466    // If the argument is 0 or a number in range 10^-6 <= n < INT_MAX+1, then parseInt
     467    // results in a truncation to integer. In the case of -0, this is converted to 0.
     468    //
     469    // This is also a truncation for values in the range INT_MAX+1 <= n < 10^21,
     470    // however these values cannot be trivially truncated to int since 10^21 exceeds
     471    // even the int64_t range. Negative numbers are a little trickier, the case for
     472    // values in the range -10^21 < n <= -1 are similar to those for integer, but
     473    // values in the range -1 < n <= -10^-6 need to truncate to -0, not 0.
     474    static const double tenToTheMinus6 = 0.000001;
     475    static const double intMaxPlusOne = 2147483648.0;
    466476    double n;
    467     if (value.getNumber(n) && n >= 0 && n < INT_MAX && exec->argument(1).isUndefined())
    468         return JSValue::encode(jsNumber(static_cast<int>(n)));
    469 
    470     int32_t radix = exec->argument(1).toInt32(exec);
    471 
    472     if (radix != 0 && radix != 10)
    473         return JSValue::encode(jsNumber(parseInt(value.toString(exec), radix)));
    474 
    475     if (value.isInt32())
    476         return JSValue::encode(value);
    477 
    478     if (value.isDouble()) {
    479         double d = value.asDouble();
    480         if (isfinite(d))
    481             return JSValue::encode(jsNumber((d > 0) ? floor(d) : ceil(d)));
    482         return JSValue::encode(jsNaN());
    483     }
    484 
    485     return JSValue::encode(jsNumber(parseInt(value.toString(exec), radix)));
     477    if (value.getNumber(n) && ((n < intMaxPlusOne && n >= tenToTheMinus6) || !n) && radixValue.isUndefinedOrNull())
     478        return JSValue::encode(jsNumber(static_cast<int32_t>(n)));
     479
     480    // If ToString throws, we shouldn't call ToInt32.
     481    UString s = value.toString(exec);
     482    if (exec->hadException())
     483        return JSValue::encode(jsUndefined());
     484
     485    return JSValue::encode(jsNumber(parseInt(s, radixValue.toInt32(exec))));
    486486}
    487487
Note: See TracChangeset for help on using the changeset viewer.