Ignore:
Timestamp:
Oct 24, 2007, 1:14:32 AM (18 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • separate out the code to create a hash table the first time from the code to rehash

SunSpider claims this was a 0.7% speedup.

  • kjs/property_map.cpp: (KJS::PropertyMap::expand): Changed to call either createTable or rehash. (KJS::PropertyMap::createTable): Added. For the case where we had no table. (KJS::PropertyMap::rehash): Removed code needed only in the case where we had no table.
  • kjs/property_map.h: Added createTable.
File:
1 edited

Legend:

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

    r26847 r26958  
    412412void PropertyMap::expand()
    413413{
    414     Table *oldTable = m_u.table;
    415     int oldTableSize = m_usingTable ? oldTable->size : 0;   
    416     rehash(oldTableSize ? oldTableSize * 2 : 16);
     414    if (!m_usingTable)
     415        createTable();
     416    else
     417        rehash(m_u.table->size * 2);
    417418}
    418419
    419420void PropertyMap::rehash()
    420421{
     422    ASSERT(m_usingTable);
    421423    ASSERT(m_u.table);
    422424    ASSERT(m_u.table->size);
     
    424426}
    425427
    426 void PropertyMap::rehash(int newTableSize)
    427 {
     428void PropertyMap::createTable()
     429{
     430    const int newTableSize = 16;
     431
     432    ASSERT(!m_usingTable);
     433
    428434    checkConsistency();
    429435
     
    432438#endif
    433439
    434     Table *oldTable = m_usingTable ? m_u.table : 0;
    435     int oldTableSize = m_usingTable ? oldTable->size : 0;
    436     int oldTableKeyCount = m_usingTable ? oldTable->keyCount : 0;
    437    
    438     m_u.table = (Table *)fastCalloc(1, sizeof(Table) + (newTableSize - 1) * sizeof(Entry) );
     440    m_u.table = (Table *)fastCalloc(1, sizeof(Table) + (newTableSize - 1) * sizeof(Entry));
    439441    m_u.table->size = newTableSize;
    440442    m_u.table->sizeMask = newTableSize - 1;
    441     m_u.table->keyCount = oldTableKeyCount;
    442443    m_usingTable = true;
    443444
     
    447448        insert(key, oldSingleEntryValue, m_singleEntryAttributes, 0);
    448449        m_singleEntryKey = 0;
    449         // update the count, because single entries don't count towards
    450         // the table key count
    451         ++m_u.table->keyCount;
    452         ASSERT(m_u.table->keyCount == 1);
    453     }
    454 #endif
     450        m_u.table->keyCount = 1;
     451    }
     452#endif
     453
     454    checkConsistency();
     455}
     456
     457void PropertyMap::rehash(int newTableSize)
     458{
     459    ASSERT(!m_singleEntryKey);
     460    ASSERT(m_u.table);
     461    ASSERT(m_usingTable);
     462
     463    checkConsistency();
     464
     465    Table* oldTable = m_u.table;
     466    int oldTableSize = oldTable->size;
     467    int oldTableKeyCount = oldTable->keyCount;
     468   
     469    m_u.table = (Table *)fastCalloc(1, sizeof(Table) + (newTableSize - 1) * sizeof(Entry));
     470    m_u.table->size = newTableSize;
     471    m_u.table->sizeMask = newTableSize - 1;
     472    m_u.table->keyCount = oldTableKeyCount;
    455473   
    456474    int lastIndexUsed = 0;
Note: See TracChangeset for help on using the changeset viewer.