⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 184009 in webkit


Ignore:
Timestamp:
May 8, 2015, 1:07:29 PM (11 years ago)
Author:
oliver@apple.com
Message:

MapDataImpl::add() shouldn't do the same hash lookup twice.
https://bugs.webkit.org/show_bug.cgi?id=144759

Reviewed by Gavin Barraclough.

We don't actually need to do a double lookup here, all we need to
do is update the index to point to the correct m_size.

  • runtime/MapDataInlines.h:

(JSC::JSIterator>::add):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r184006 r184009  
     12015-05-08  Oliver Hunt  <oliver@apple.com>
     2
     3        MapDataImpl::add() shouldn't do the same hash lookup twice.
     4        https://bugs.webkit.org/show_bug.cgi?id=144759
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        We don't actually need to do a double lookup here, all we need to
     9        do is update the index to point to the correct m_size.
     10
     11        * runtime/MapDataInlines.h:
     12        (JSC::JSIterator>::add):
     13
    1142015-05-08  Andreas Kling  <akling@apple.com>
    215
  • trunk/Source/JavaScriptCore/runtime/MapDataInlines.h

    r181968 r184009  
    9292inline Entry* MapDataImpl<Entry, JSIterator>::add(ExecState* exec, JSCell* owner, Map& map, Key key, KeyType keyValue)
    9393{
    94     typename Map::iterator location = map.find(key);
    95     if (location != map.end())
    96         return &m_entries[location->value];
    97 
    98     if (!ensureSpaceForAppend(exec, owner))
     94    auto result = map.add(key, m_size);
     95    if (!result.isNewEntry)
     96        return &m_entries[result.iterator->value];
     97
     98    if (!ensureSpaceForAppend(exec, owner)) {
     99        map.remove(result.iterator);
    99100        return 0;
    100 
    101     auto result = map.add(key, m_size);
    102     RELEASE_ASSERT(result.isNewEntry);
     101    }
     102
     103    result.iterator->value = m_size;
    103104    Entry* entry = &m_entries[m_size++];
    104105    new (entry) Entry();
     
    175176    ASSERT(shouldPack());
    176177    int32_t newEnd = 0;
    177     RELEASE_ASSERT(newCapacity > 0);
     178    ASSERT(newCapacity > 0);
     179    RELEASE_ASSERT(newCapacity > m_size);
     180
    178181    for (int32_t i = 0; i < m_size; i++) {
    179182        Entry& entry = m_entries[i];
     
    195198
    196199    // Fixup for the hashmaps
    197     for (auto ptr = m_valueKeyedTable.begin(); ptr != m_valueKeyedTable.end(); ++ptr)
    198         ptr->value = m_entries[ptr->value].key().get().asInt32();
    199     for (auto ptr = m_cellKeyedTable.begin(); ptr != m_cellKeyedTable.end(); ++ptr)
    200         ptr->value = m_entries[ptr->value].key().get().asInt32();
    201     for (auto ptr = m_stringKeyedTable.begin(); ptr != m_stringKeyedTable.end(); ++ptr)
    202         ptr->value = m_entries[ptr->value].key().get().asInt32();
    203     for (auto ptr = m_symbolKeyedTable.begin(); ptr != m_symbolKeyedTable.end(); ++ptr)
    204         ptr->value = m_entries[ptr->value].key().get().asInt32();
     200    for (auto ptr = m_valueKeyedTable.begin(); ptr != m_valueKeyedTable.end(); ++ptr) {
     201        if (ptr->value < m_size)
     202            ptr->value = m_entries[ptr->value].key().get().asInt32();
     203    }
     204    for (auto ptr = m_cellKeyedTable.begin(); ptr != m_cellKeyedTable.end(); ++ptr) {
     205        if (ptr->value < m_size)
     206            ptr->value = m_entries[ptr->value].key().get().asInt32();
     207    }
     208    for (auto ptr = m_stringKeyedTable.begin(); ptr != m_stringKeyedTable.end(); ++ptr) {
     209        if (ptr->value < m_size)
     210            ptr->value = m_entries[ptr->value].key().get().asInt32();
     211    }
     212    for (auto ptr = m_symbolKeyedTable.begin(); ptr != m_symbolKeyedTable.end(); ++ptr) {
     213        if (ptr->value < m_size)
     214            ptr->value = m_entries[ptr->value].key().get().asInt32();
     215    }
    205216
    206217    ASSERT((m_size - newEnd) == m_deletedCount);
Note: See TracChangeset for help on using the changeset viewer.