Changeset 34964 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
Jul 2, 2008, 5:47:00 PM (17 years ago)
Author:
[email protected]
Message:

2008-07-02 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.

Optimized a[n] get for cases where a is an array or a string, and a[n]
put for cases where a is an array.


SunSpider says 9.0% faster.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/Machine.cpp

    r34947 r34964  
    4646#include "RegExpPrototype.h"
    4747#include "Register.h"
     48#include "collector.h"
    4849#include "debugger.h"
    4950#include "operations.h"
     
    476477{
    477478    privateExecute(InitializeAndReturn);
     479   
     480    // Bizarrely, calling fastMalloc here is faster than allocating space on the stack.
     481    void* storage = fastMalloc(sizeof(CollectorBlock));
     482
     483    JSArray* jsArray = new (storage) JSArray(jsNull(), 0);
     484    m_jsArrayVptr = jsArray->vptr();
     485    jsArray->~JSCell();
     486
     487    JSString* jsString = new (storage) JSString("");
     488    m_jsStringVptr = jsString->vptr();
     489    jsString->~JSCell();
     490   
     491    fastFree(storage);
    478492}
    479493
     
    18351849
    18361850        bool isUInt32 = JSImmediate::getUInt32(subscript, i);
    1837         if (LIKELY(isUInt32))
    1838             result = baseValue->get(exec, i);
    1839         else {
     1851        if (LIKELY(isUInt32)) {
     1852            if (isJSArray(baseValue)) {
     1853                JSArray* jsArray = static_cast<JSArray*>(baseValue);
     1854                if (jsArray->canGetIndex(i))
     1855                    result = jsArray->getIndex(i);
     1856                else
     1857                    result = jsArray->JSArray::get(exec, i);
     1858            } else if (isJSString(baseValue) && static_cast<JSString*>(baseValue)->canGetIndex(i))
     1859                result = static_cast<JSString*>(baseValue)->getIndex(exec, i);
     1860            else
     1861                result = baseValue->get(exec, i);
     1862        } else {
    18401863            Identifier property(exec, subscript->toString(exec));
    18411864            result = baseValue->get(exec, property);
     
    18681891
    18691892        bool isUInt32 = JSImmediate::getUInt32(subscript, i);
    1870         if (LIKELY(isUInt32))
    1871             baseValue->put(exec, i, r[value].u.jsValue);
    1872         else {
     1893        if (LIKELY(isUInt32)) {
     1894            if (isJSArray(baseValue)) {
     1895                JSArray* jsArray = static_cast<JSArray*>(baseValue);
     1896                if (jsArray->canSetIndex(i))
     1897                    jsArray->setIndex(i, r[value].u.jsValue);
     1898                else
     1899                    jsArray->JSArray::put(exec, i, r[value].u.jsValue);
     1900            } else
     1901                baseValue->put(exec, i, r[value].u.jsValue);
     1902        } else {
    18731903            Identifier property(exec, subscript->toString(exec));
    18741904            if (!exec->hadException()) // Don't put to an object if toString threw an exception.
Note: See TracChangeset for help on using the changeset viewer.