Changeset 2777 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 20, 2002, 12:53:04 AM (23 years ago)
Author:
darin
Message:
  • add a couple of list operations to avoid clearing lists so much during sorting; gives 1.5% iBench
  • kjs/types.h: Added replaceFirst/replaceLast.
  • kjs/types.cpp: (List::replaceFirst), (List::replaceLast): Added.
  • kjs/array_object.cpp: (compareWithCompareFunctionForQSort): Use replaceFirst/replaceLast.
  • kjs/property_map.cpp: Put in an ifdef so I can re-add/remove the single entry to see if it has outlived its usefulness. (It hasn't yet.)
Location:
trunk/JavaScriptCore/kjs
Files:
4 edited

Legend:

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

    r2760 r2777  
    215215        , compareFunction(cf)
    216216        , globalObject(e->interpreter()->globalObject())
    217     { }
     217    {
     218        arguments.append(Undefined());
     219        arguments.append(Undefined());
     220    }
    218221
    219222    ExecState *exec;
     
    229232    CompareWithCompareFunctionArguments *args = compareWithCompareFunctionArguments;
    230233   
    231     args->arguments.clear();
    232     args->arguments.append(*(ValueImp **)a);
    233     args->arguments.append(*(ValueImp **)b);
     234    args->arguments.replaceFirst(*(ValueImp **)a);
     235    args->arguments.replaceLast(*(ValueImp **)b);
    234236    return args->compareFunction->call(args->exec, args->globalObject, args->arguments)
    235237        .toInt32(args->exec);
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r2776 r2777  
    2626#include "reference_list.h"
    2727
     28// At the time I added this, the optimization still gave a 1.5% performance boost.
     29#define USE_SINGLE_ENTRY 1
     30
    2831namespace KJS {
    2932
     
    3639PropertyMap::~PropertyMap()
    3740{
     41#if USE_SINGLE_ENTRY
    3842    UString::Rep *key = _singleEntry.key;
    3943    if (key)
    4044        key->deref();
     45#endif
    4146    for (int i = 0; i < _tableSize; i++) {
    42         key = _table[i].key;
     47        UString::Rep *key = _table[i].key;
    4348        if (key)
    4449            key->deref();
     
    4954void PropertyMap::clear()
    5055{
     56#if USE_SINGLE_ENTRY
    5157    UString::Rep *key = _singleEntry.key;
    5258    if (key) {
     
    5460        _singleEntry.key = 0;
    5561    }
     62#endif
    5663    for (int i = 0; i < _tableSize; i++) {
    5764        UString::Rep *key = _table[i].key;
     
    7178ValueImp *PropertyMap::get(const Identifier &name, int &attributes) const
    7279{
    73     if (!_table) {
     80    UString::Rep *rep = name._ustring.rep;
     81   
     82    if (!_table) {
     83 #if USE_SINGLE_ENTRY
    7484        UString::Rep *key = _singleEntry.key;
    75         if (name._ustring.rep == key) {
     85        if (rep == key) {
    7686            attributes = _singleEntry.attributes;
    7787            return _singleEntry.value;
    7888        }
     89#endif
    7990        return 0;
    8091    }
    8192   
    82     int i = hash(name._ustring.rep);
     93    int i = hash(rep);
    8394    while (UString::Rep *key = _table[i].key) {
    84         if (name._ustring.rep == key) {
     95        if (rep == key) {
    8596            attributes = _table[i].attributes;
    8697            return _table[i].value;
     
    93104ValueImp *PropertyMap::get(const Identifier &name) const
    94105{
    95     if (!_table) {
     106    UString::Rep *rep = name._ustring.rep;
     107
     108    if (!_table) {
     109#if USE_SINGLE_ENTRY
    96110        UString::Rep *key = _singleEntry.key;
    97         if (name._ustring.rep == key)
     111        if (rep == key)
    98112            return _singleEntry.value;
     113#endif
    99114        return 0;
    100115    }
    101116   
    102     int i = hash(name._ustring.rep);
     117    int i = hash(rep);
    103118    while (UString::Rep *key = _table[i].key) {
    104         if (name._ustring.rep == key)
     119        if (rep == key)
    105120            return _table[i].value;
    106121        i = (i + 1) & _tableSizeMask;
     
    111126void PropertyMap::put(const Identifier &name, ValueImp *value, int attributes)
    112127{
     128    UString::Rep *rep = name._ustring.rep;
     129
     130#if USE_SINGLE_ENTRY
    113131    if (!_table) {
    114132        UString::Rep *key = _singleEntry.key;
    115133        if (key) {
    116             if (name._ustring.rep == key) {
     134            if (rep == key) {
    117135                _singleEntry.value = value;
    118136                return;
    119137            }
    120138        } else {
    121             name._ustring.rep->ref();
    122             _singleEntry.key = name._ustring.rep;
     139            rep->ref();
     140            _singleEntry.key = rep;
    123141            _singleEntry.value = value;
    124142            _singleEntry.attributes = attributes;
     
    127145        }
    128146    }
     147#endif
    129148
    130149    if (_keyCount * 2 >= _tableSize)
    131150        expand();
    132151   
    133     int i = hash(name._ustring.rep);
     152    int i = hash(rep);
    134153    while (UString::Rep *key = _table[i].key) {
    135         if (name._ustring.rep == key) {
     154        if (rep == key) {
    136155            // Put a new value in an existing hash table entry.
    137156            _table[i].value = value;
     
    143162   
    144163    // Create a new hash table entry.
    145     name._ustring.rep->ref();
    146     _table[i].key = name._ustring.rep;
     164    rep->ref();
     165    _table[i].key = rep;
    147166    _table[i].value = value;
    148167    _table[i].attributes = attributes;
     
    170189    _table = (Entry *)calloc(_tableSize, sizeof(Entry));
    171190
     191#if USE_SINGLE_ENTRY
    172192    UString::Rep *key = _singleEntry.key;
    173193    if (key) {
     
    175195        _singleEntry.key = 0;
    176196    }
     197#endif
    177198   
    178199    for (int i = 0; i != oldTableSize; ++i) {
    179         key = oldTable[i].key;
     200        UString::Rep *key = oldTable[i].key;
    180201        if (key)
    181202            insert(key, oldTable[i].value, oldTable[i].attributes);
     
    187208void PropertyMap::remove(const Identifier &name)
    188209{
     210    UString::Rep *rep = name._ustring.rep;
     211
    189212    UString::Rep *key;
    190213
    191214    if (!_table) {
     215#if USE_SINGLE_ENTRY
    192216        key = _singleEntry.key;
    193         if (name._ustring.rep == key) {
     217        if (rep == key) {
    194218            key->deref();
    195219            _singleEntry.key = 0;
    196220            _keyCount = 0;
    197221        }
     222#endif
    198223        return;
    199224    }
    200225
    201226    // Find the thing to remove.
    202     int i = hash(name._ustring.rep);
     227    int i = hash(rep);
    203228    while ((key = _table[i].key)) {
    204         if (name._ustring.rep == key)
     229        if (rep == key)
    205230            break;
    206231        i = (i + 1) & _tableSizeMask;
     
    227252void PropertyMap::mark() const
    228253{
     254#if USE_SINGLE_ENTRY
    229255    if (_singleEntry.key) {
    230256        ValueImp *v = _singleEntry.value;
     
    232258            v->mark();
    233259    }
     260#endif
    234261    for (int i = 0; i != _tableSize; ++i) {
    235262        if (_table[i].key) {
     
    243270void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, const Object &base) const
    244271{
     272#if USE_SINGLE_ENTRY
    245273    UString::Rep *key = _singleEntry.key;
    246274    if (key && !(_singleEntry.attributes & DontEnum))
    247275        list.append(Reference(base, Identifier(key)));
     276#endif
    248277    for (int i = 0; i != _tableSize; ++i) {
    249278        UString::Rep *key = _table[i].key;
  • trunk/JavaScriptCore/kjs/types.cpp

    r2757 r2777  
    350350  other.hook = tmp;
    351351}
     352
     353void List::replaceFirst(ValueImp *v)
     354{
     355    ListNode *n = hook->next;
     356    if (!m_needsMarking) {
     357      v->ref();
     358      n->member->deref();
     359    }
     360    n->member = v;
     361}
     362
     363void List::replaceLast(ValueImp *v)
     364{
     365    ListNode *n = hook->prev;
     366    if (!m_needsMarking) {
     367      v->ref();
     368      n->member->deref();
     369    }
     370    n->member = v;
     371}
  • trunk/JavaScriptCore/kjs/types.h

    r2757 r2777  
    184184     */
    185185    static const List &empty();
     186   
    186187    void mark();
     188   
     189    void replaceFirst(ValueImp *);
     190    void replaceLast(ValueImp *);
     191   
    187192  private:
    188193
Note: See TracChangeset for help on using the changeset viewer.