Ignore:
Timestamp:
Feb 13, 2009, 3:28:04 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-02-13 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.


Fixed <rdar://problem/6584057> Optimize sort by JS numeric comparison
function not to run the comparison function


  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::CodeBlock):
  • bytecode/CodeBlock.h: (JSC::CodeBlock::setIsNumericCompareFunction): (JSC::CodeBlock::isNumericCompareFunction): Added the ability to track whether a CodeBlock performs a sort-like numeric comparison.
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::generate): Set the isNumericCompareFunction bit after compiling.
  • parser/Nodes.cpp: (JSC::FunctionBodyNode::emitBytecode): Fixed a bug that caused us to codegen an extra return at the end of all functions (eek!), since this made it harder / weirder to detect the numeric comparison pattern in bytecode.
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncSort): Use the isNumericCompareFunction bit to do a faster sort if we can.
  • runtime/FunctionConstructor.cpp: (JSC::extractFunctionBody): (JSC::constructFunction):
  • runtime/FunctionConstructor.h: Renamed and exported extractFunctionBody for use in initializing lazyNumericCompareFunction.
  • runtime/JSArray.cpp: (JSC::compareNumbersForQSort): (JSC::compareByStringPairForQSort): (JSC::JSArray::sortNumeric): (JSC::JSArray::sort):
  • runtime/JSArray.h: Added a fast numeric sort. Renamed ArrayQSortPair to be more specific since we do different kinds of qsort now.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): (JSC::JSGlobalData::numericCompareFunction): (JSC::JSGlobalData::ClientData::~ClientData):
  • runtime/JSGlobalData.h: Added helper data for computing the isNumericCompareFunction bit.

LayoutTests:

2009-02-13 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Added a test for an edge case in <rdar://problem/6584057>.

  • fast/js/resources/sort-non-numbers.js: Added.
  • fast/js/sort-non-numbers.html: Added.
  • fast/js/sort-non-numbers-expected.txt: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/Nodes.cpp

    r40962 r40993  
    26492649    generator.emitDebugHook(DidEnterCallFrame, firstLine(), lastLine());
    26502650    statementListEmitCode(children(), generator, generator.ignoredResult());
    2651     if (!children().size() || !children().last()->isReturnNode()) {
    2652         RegisterID* r0 = generator.emitLoad(0, jsUndefined());
    2653         generator.emitDebugHook(WillLeaveCallFrame, firstLine(), lastLine());
    2654         generator.emitReturn(r0);
    2655     }
     2651    if (children().size() && children().last()->isBlock()) {
     2652        BlockNode* blockNode = static_cast<BlockNode*>(children().last().get());
     2653        if (blockNode->children().size() && blockNode->children().last()->isReturnNode())
     2654            return 0;
     2655    }
     2656
     2657    RegisterID* r0 = generator.emitLoad(0, jsUndefined());
     2658    generator.emitDebugHook(WillLeaveCallFrame, firstLine(), lastLine());
     2659    generator.emitReturn(r0);
    26562660    return 0;
    26572661}
Note: See TracChangeset for help on using the changeset viewer.