Ignore:
Timestamp:
Sep 22, 2008, 2:04:45 PM (17 years ago)
Author:
Darin Adler
Message:

2008-09-22 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

3% or so speedup on DeltaBlue benchmark.

  • kjs/ArrayPrototype.cpp: (JSC::arrayProtoFuncPop): Call JSArray::pop when appropriate. (JSC::arrayProtoFuncPush): Call JSArray::push when appropriate.
  • kjs/JSArray.cpp: (JSC::JSArray::putSlowCase): Set m_fastAccessCutoff when appropriate, getting us into the fast code path. (JSC::JSArray::pop): Added. (JSC::JSArray::push): Added.
  • kjs/JSArray.h: Added push and pop.
  • kjs/operations.cpp: (JSC::throwOutOfMemoryError): Don't inline this. Helps us avoid PIC branches.
File:
1 edited

Legend:

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

    r36726 r36778  
    312312        if (increaseVectorLength(i + 1)) {
    313313            storage = m_storage;
    314             ++storage->m_numValuesInVector;
    315314            storage->m_vector[i] = value;
     315            if (++storage->m_numValuesInVector == storage->m_length)
     316                m_fastAccessCutoff = storage->m_length;
    316317            checkConsistency();
    317318        } else
     
    509510}
    510511
     512JSValue* JSArray::pop()
     513{
     514    checkConsistency();
     515
     516    unsigned length = m_storage->m_length;
     517    if (!length)
     518        return jsUndefined();
     519
     520    --length;
     521
     522    JSValue* result;
     523
     524    if (m_fastAccessCutoff > length) {
     525        JSValue*& valueSlot = m_storage->m_vector[length];
     526        result = valueSlot;
     527        ASSERT(result);
     528        valueSlot = 0;
     529        --m_storage->m_numValuesInVector;
     530        m_fastAccessCutoff = length;
     531    } else if (length < m_storage->m_vectorLength) {
     532        JSValue*& valueSlot = m_storage->m_vector[length];
     533        result = valueSlot;
     534        valueSlot = 0;
     535        if (result)
     536            --m_storage->m_numValuesInVector;
     537        else
     538            result = jsUndefined();
     539    } else {
     540        result = jsUndefined();
     541        if (SparseArrayValueMap* map = m_storage->m_sparseValueMap) {
     542            SparseArrayValueMap::iterator it = map->find(length);
     543            if (it != map->end()) {
     544                result = it->second;
     545                map->remove(it);
     546                if (map->isEmpty()) {
     547                    delete map;
     548                    m_storage->m_sparseValueMap = 0;
     549                }
     550            }
     551        }
     552    }
     553
     554    m_storage->m_length = length;
     555
     556    checkConsistency();
     557
     558    return result;
     559}
     560
     561void JSArray::push(ExecState* exec, JSValue* value)
     562{
     563    checkConsistency();
     564
     565    if (m_storage->m_length < m_storage->m_vectorLength) {
     566        ASSERT(!m_storage->m_vector[m_storage->m_length]);
     567        m_storage->m_vector[m_storage->m_length] = value;
     568        if (++m_storage->m_numValuesInVector == ++m_storage->m_length)
     569            m_fastAccessCutoff = m_storage->m_length;
     570        checkConsistency();
     571        return;
     572    }
     573
     574    if (m_storage->m_length < MIN_SPARSE_ARRAY_INDEX) {
     575        SparseArrayValueMap* map = m_storage->m_sparseValueMap;
     576        if (!map || map->isEmpty()) {
     577            if (increaseVectorLength(m_storage->m_length + 1)) {
     578                m_storage->m_vector[m_storage->m_length] = value;
     579                if (++m_storage->m_numValuesInVector == ++m_storage->m_length)
     580                    m_fastAccessCutoff = m_storage->m_length;
     581                checkConsistency();
     582                return;
     583            }
     584            checkConsistency();
     585            throwOutOfMemoryError(exec);
     586            return;
     587        }
     588    }
     589
     590    putSlowCase(exec, m_storage->m_length++, value);
     591}
     592
    511593void JSArray::mark()
    512594{
Note: See TracChangeset for help on using the changeset viewer.