Ignore:
Timestamp:
Nov 21, 2002, 7:39:47 AM (23 years ago)
Author:
darin
Message:
  • add self-check to property map in hopes of finding the cnet.com bug
  • kjs/property_map.h: Add check() function.
  • kjs/property_map.cpp: Add the checking, controlled by DO_CONSISTENCY_CHECK.
  • fixed UChar interface so it's not so slow in debug builds
  • kjs/ustring.h: Nothing in UChar needs to be private.
  • kjs/function.cpp: (GlobalFuncImp::call):
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/identifier.cpp:
  • kjs/lexer.cpp: (Lexer::setCode), (Lexer::shift):
  • kjs/lookup.cpp: (keysMatch):
  • kjs/ustring.cpp: (UString::Rep::computeHash), (KJS::compare): Use the "uc" field instead of the "unicode()" inline function.
File:
1 edited

Legend:

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

    r2794 r2800  
    2626#include "reference_list.h"
    2727
     28#define DO_CONSISTENCY_CHECK 0
     29
    2830// At the time I added this switch, the optimization still gave a 1.5% performance boost so I couldn't remove it.
    2931#define USE_SINGLE_ENTRY 1
     32
     33#if !DO_CONSISTENCY_CHECK
     34#define check() ((void)0)
     35#endif
    3036
    3137namespace KJS {
     
    132138void PropertyMap::put(const Identifier &name, ValueImp *value, int attributes)
    133139{
     140    check();
     141
    134142    UString::Rep *rep = name._ustring.rep;
    135143   
     
    139147        if (key) {
    140148            if (rep == key) {
    141                 _singleEntry.value = value;
     149                _singleEntry.value = value;
    142150                return;
    143151            }
     
    148156            _singleEntry.attributes = attributes;
    149157            _keyCount = 1;
     158            check();
    150159            return;
    151160        }
     
    173182    _table[i].attributes = attributes;
    174183    ++_keyCount;
     184
     185    check();
    175186}
    176187
     
    188199void PropertyMap::expand()
    189200{
     201    check();
     202   
    190203    int oldTableSize = _tableSize;
    191204    Entry *oldTable = _table;
     
    210223
    211224    free(oldTable);
     225
     226    check();
    212227}
    213228
    214229void PropertyMap::remove(const Identifier &name)
    215230{
     231    check();
     232
    216233    UString::Rep *rep = name._ustring.rep;
    217234
     
    225242            _singleEntry.key = 0;
    226243            _keyCount = 0;
     244            check();
    227245        }
    228246#endif
     
    254272        insert(key, _table[i].value, _table[i].attributes);
    255273    }
     274
     275    check();
    256276}
    257277
     
    329349}
    330350
     351#if DO_CONSISTENCY_CHECK
     352
     353void PropertyMap::check()
     354{
     355    int count = 0;
     356    for (int j = 0; j != _tableSize; ++j) {
     357        UString::Rep *rep = _table[j].key;
     358        if (!rep)
     359            continue;
     360        int i = hash(rep);
     361        while (UString::Rep *key = _table[i].key) {
     362            if (rep == key)
     363                break;
     364            i = (i + 1) & _tableSizeMask;
     365        }
     366        assert(i == j);
     367        count++;
     368    }
     369#if USE_SINGLE_ENTRY
     370    if (_singleEntry.key)
     371        count++;
     372#endif
     373    assert(count == _keyCount);
     374    if (_table) {
     375        assert(_tableSize);
     376        assert(_tableSizeMask);
     377        assert(_tableSize == _tableSizeMask + 1);
     378    }
     379}
     380
     381#endif // DO_CONSISTENCY_CHECK
     382
    331383} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.