Ignore:
Timestamp:
Oct 7, 2008, 11:17:37 AM (17 years ago)
Author:
[email protected]
Message:

2008-10-07 Cameron Zwarich <[email protected]>

Rubber-stamped by Mark Rowe.

Roll out r37370.

File:
1 edited

Legend:

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

    r37370 r37381  
    7878#if !DO_PROPERTYMAP_CONSTENCY_CHECK
    7979
    80 inline void PropertyMap::checkConsistency()
     80inline void PropertyMap::checkConsistency(PropertyStorage&)
    8181{
    8282}
     
    9898    }
    9999
    100     m_deletedOffsets = other.m_deletedOffsets;
    101100    m_getterSetterFlag = other.m_getterSetterFlag;
    102101    return *this;
     
    116115}
    117116
    118 size_t PropertyMap::put(const Identifier& propertyName, unsigned attributes)
     117size_t PropertyMap::put(const Identifier& propertyName, JSValue* value, unsigned attributes, bool checkReadOnly, JSObject* slotBase, PutPropertySlot& slot, PropertyStorage& propertyStorage)
    119118{
    120119    ASSERT(!propertyName.isNull());
    121     ASSERT(get(propertyName) == WTF::notFound);
    122 
    123     checkConsistency();
     120    ASSERT(value);
     121
     122    checkConsistency(propertyStorage);
    124123
    125124    UString::Rep* rep = propertyName._ustring.rep();
    126125
    127126    if (!m_table)
    128         createTable();
     127        expand(propertyStorage);
    129128
    130129    // FIXME: Consider a fast case for tables with no deleted sentinels.
     
    144143            break;
    145144
    146         if (entryIndex == deletedSentinelIndex) {
     145        if (m_table->entries()[entryIndex - 1].key == rep) {
     146            if (checkReadOnly && (m_table->entries()[entryIndex - 1].attributes & ReadOnly))
     147                return WTF::notFound;
     148            // Put a new value in an existing hash table entry.
     149            propertyStorage[entryIndex - 2] = value;
     150            // Attributes are intentionally not updated.
     151            slot.setExistingProperty(slotBase, entryIndex - 2);
     152            return entryIndex - 2;
     153        } else if (entryIndex == deletedSentinelIndex) {
    147154            // If we find a deleted-element sentinel, remember it for use later.
    148155            if (!foundDeletedElement) {
     
    187194    m_table->entries()[entryIndex - 1].attributes = attributes;
    188195    m_table->entries()[entryIndex - 1].index = ++m_table->lastIndexUsed;
    189 
    190     unsigned newOffset;
    191     if (!m_deletedOffsets.isEmpty()) {
    192         newOffset = m_deletedOffsets.last();
    193         m_deletedOffsets.removeLast();
    194     } else
    195         newOffset = m_table->keyCount + m_table->deletedSentinelCount;
    196     m_table->entries()[entryIndex - 1].offset = newOffset;
    197 
    198196    ++m_table->keyCount;
    199197
     198    propertyStorage[entryIndex - 2] = value;
     199
    200200    if ((m_table->keyCount + m_table->deletedSentinelCount) * 2 >= m_table->size)
    201         expand();
    202 
    203     checkConsistency();
    204     return newOffset;
    205 }
    206 
    207 size_t PropertyMap::remove(const Identifier& propertyName)
     201        expand(propertyStorage);
     202
     203    checkConsistency(propertyStorage);
     204    slot.setNewProperty(slotBase, entryIndex - 2);
     205    return entryIndex - 2;
     206}
     207
     208void PropertyMap::remove(const Identifier& propertyName, PropertyStorage& propertyStorage)
    208209{
    209210    ASSERT(!propertyName.isNull());
    210211
    211     checkConsistency();
     212    checkConsistency(propertyStorage);
    212213
    213214    UString::Rep* rep = propertyName._ustring.rep();
    214215
    215216    if (!m_table)
    216         return WTF::notFound;
    217 
     217        return;
    218218
    219219#if DUMP_PROPERTYMAP_STATS
     
    230230        entryIndex = m_table->entryIndices[i & m_table->sizeMask];
    231231        if (entryIndex == emptyEntryIndex)
    232             return WTF::notFound;
     232            return;
    233233
    234234        key = m_table->entries()[entryIndex - 1].key;
     
    253253    // the entry so we can iterate all the entries as needed.
    254254    m_table->entryIndices[i & m_table->sizeMask] = deletedSentinelIndex;
    255 
    256     size_t offset = m_table->entries()[entryIndex - 1].offset;
    257 
    258255    key->deref();
    259256    m_table->entries()[entryIndex - 1].key = 0;
    260257    m_table->entries()[entryIndex - 1].attributes = 0;
    261     m_table->entries()[entryIndex - 1].offset = 0;
    262     m_deletedOffsets.append(offset);
     258
     259    propertyStorage[entryIndex - 2] = jsUndefined();
    263260
    264261    ASSERT(m_table->keyCount >= 1);
     
    267264
    268265    if (m_table->deletedSentinelCount * 4 >= m_table->size)
    269         rehash();
    270 
    271     checkConsistency();
    272     return offset;
    273 }
    274 
    275 size_t PropertyMap::get(const Identifier& propertyName, unsigned& attributes)
     266        rehash(propertyStorage);
     267
     268    checkConsistency(propertyStorage);
     269}
     270
     271size_t PropertyMap::getOffset(const Identifier& propertyName, unsigned& attributes)
    276272{
    277273    ASSERT(!propertyName.isNull());
     
    294290    if (rep == m_table->entries()[entryIndex - 1].key) {
    295291        attributes = m_table->entries()[entryIndex - 1].attributes;
    296         return m_table->entries()[entryIndex - 1].offset;
     292        return entryIndex - 2;
    297293    }
    298294
     
    316312        if (rep == m_table->entries()[entryIndex - 1].key) {
    317313            attributes = m_table->entries()[entryIndex - 1].attributes;
    318             return m_table->entries()[entryIndex - 1].offset;
    319         }
    320     }
    321 }
    322 
    323 void PropertyMap::insert(const Entry& entry)
     314            return entryIndex - 2;
     315        }
     316    }
     317}
     318
     319void PropertyMap::insert(const Entry& entry, JSValue* value, PropertyStorage& propertyStorage)
    324320{
    325321    ASSERT(m_table);
     
    355351    m_table->entries()[entryIndex - 1] = entry;
    356352
     353    propertyStorage[entryIndex - 2] = value;
     354
    357355    ++m_table->keyCount;
    358356}
    359357
    360 void PropertyMap::expand()
     358void PropertyMap::expand(PropertyStorage& propertyStorage)
     359{
     360    if (!m_table)
     361        createTable(propertyStorage);
     362    else
     363        rehash(m_table->size * 2, propertyStorage);
     364}
     365
     366void PropertyMap::rehash(PropertyStorage& propertyStorage)
    361367{
    362368    ASSERT(m_table);
    363     rehash(m_table->size * 2);
    364 }
    365 
    366 void PropertyMap::createTable()
     369    ASSERT(m_table->size);
     370    rehash(m_table->size, propertyStorage);
     371}
     372
     373void PropertyMap::createTable(PropertyStorage& propertyStorage)
    367374{
    368375    const unsigned newTableSize = 16;
     
    370377    ASSERT(!m_table);
    371378
    372     checkConsistency();
     379    checkConsistency(propertyStorage);
    373380
    374381    m_table = static_cast<Table*>(fastZeroedMalloc(Table::allocationSize(newTableSize)));
     
    376383    m_table->sizeMask = newTableSize - 1;
    377384
    378     checkConsistency();
    379 }
    380 
    381 void PropertyMap::rehash()
     385    checkConsistency(propertyStorage);
     386}
     387
     388void PropertyMap::rehash(unsigned newTableSize, PropertyStorage& propertyStorage)
    382389{
    383390    ASSERT(m_table);
    384     ASSERT(m_table->size);
    385     rehash(m_table->size);
    386 }
    387 
    388 void PropertyMap::rehash(unsigned newTableSize)
    389 {
    390     ASSERT(m_table);
    391 
    392     checkConsistency();
     391
     392    checkConsistency(propertyStorage);
    393393
    394394    Table* oldTable = m_table;
     395    JSValue** oldPropertStorage = propertyStorage;
    395396
    396397    m_table = static_cast<Table*>(fastZeroedMalloc(Table::allocationSize(newTableSize)));
    397398    m_table->size = newTableSize;
    398399    m_table->sizeMask = newTableSize - 1;
     400
     401    propertyStorage = new JSValue*[m_table->size];
    399402
    400403    unsigned lastIndexUsed = 0;
     
    403406        if (oldTable->entries()[i].key) {
    404407            lastIndexUsed = max(oldTable->entries()[i].index, lastIndexUsed);
    405             insert(oldTable->entries()[i]);
     408            insert(oldTable->entries()[i], oldPropertStorage[i - 1], propertyStorage);
    406409        }
    407410    }
     
    409412
    410413    fastFree(oldTable);
    411 
    412     checkConsistency();
     414    delete [] oldPropertStorage;
     415
     416    checkConsistency(propertyStorage);
    413417}
    414418
     
    482486#if DO_PROPERTYMAP_CONSTENCY_CHECK
    483487
    484 void PropertyMap::checkConsistency()
     488void PropertyMap::checkConsistency(PropertyStorage& propertyStorage)
    485489{
    486490    if (!m_table)
     
    522526    for (unsigned c = 1; c <= m_table->keyCount + m_table->deletedSentinelCount; ++c) {
    523527        UString::Rep* rep = m_table->entries()[c].key;
    524         if (!rep)
     528        if (!rep) {
     529            ASSERT(propertyStorage[c - 1]->isUndefined());
    525530            continue;
     531        }
    526532        ++nonEmptyEntryCount;
    527533        unsigned i = rep->computedHash();
Note: See TracChangeset for help on using the changeset viewer.