Ignore:
Timestamp:
Apr 16, 2009, 12:24:59 AM (16 years ago)
Author:
[email protected]
Message:

Improve performance of Array.sort

Reviewed by Gavin Barraclough.

Cache the VM entry for Array.sort when using a JS comparison function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSArray.cpp

    r42337 r42571  
    2525
    2626#include "ArrayPrototype.h"
     27#include "CachedCall.h"
    2728#include "PropertyNameArray.h"
    2829#include <wtf/AVLTree.h>
    2930#include <wtf/Assertions.h>
     31#include <wtf/OwnPtr.h>
    3032#include <Operations.h>
    3133
     
    746748    const CallData* m_compareCallData;
    747749    JSValuePtr m_globalThisValue;
     750    OwnPtr<CachedCall> m_cachedCall;
    748751
    749752    handle get_less(handle h) { return m_nodes[h].lt & 0x7FFFFFFF; }
     
    781784            return 1;
    782785
    783         ArgList arguments;
    784         arguments.append(va);
    785         arguments.append(vb);
    786         double compareResult = call(m_exec, m_compareFunction, m_compareCallType, *m_compareCallData, m_globalThisValue, arguments).toNumber(m_exec);
     786        double compareResult;
     787        if (m_cachedCall) {
     788            m_cachedCall->setThis(m_globalThisValue);
     789            m_cachedCall->setArgument(0, va);
     790            m_cachedCall->setArgument(1, vb);
     791            compareResult = m_cachedCall->call().toNumber(m_exec);
     792        } else {
     793            ArgList arguments;
     794            arguments.append(va);
     795            arguments.append(vb);
     796            compareResult = call(m_exec, m_compareFunction, m_compareCallType, *m_compareCallData, m_globalThisValue, arguments).toNumber(m_exec);
     797        }
    787798        return (compareResult < 0) ? -1 : 1; // Not passing equality through, because we need to store all values, even if equivalent.
    788799    }
     
    818829    tree.abstractor().m_globalThisValue = exec->globalThisValue();
    819830    tree.abstractor().m_nodes.resize(usedVectorLength + (m_storage->m_sparseValueMap ? m_storage->m_sparseValueMap->size() : 0));
     831
     832    if (callType == CallTypeJS)
     833        tree.abstractor().m_cachedCall.set(new CachedCall(exec, asFunction(compareFunction), 2, exec->exceptionSlot()));
    820834
    821835    if (!tree.abstractor().m_nodes.begin()) {
Note: See TracChangeset for help on using the changeset viewer.