Title: [184009] trunk/Source/_javascript_Core
Revision
184009
Author
oli...@apple.com
Date
2015-05-08 13:07:29 -0700 (Fri, 08 May 2015)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (184008 => 184009)


--- trunk/Source/_javascript_Core/ChangeLog	2015-05-08 19:43:59 UTC (rev 184008)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-05-08 20:07:29 UTC (rev 184009)
@@ -1,3 +1,16 @@
+2015-05-08  Oliver Hunt  <oli...@apple.com>
+
+        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):
+
 2015-05-08  Andreas Kling  <akl...@apple.com>
 
         Micro-optimize JSON serialization of string primitives.

Modified: trunk/Source/_javascript_Core/runtime/MapDataInlines.h (184008 => 184009)


--- trunk/Source/_javascript_Core/runtime/MapDataInlines.h	2015-05-08 19:43:59 UTC (rev 184008)
+++ trunk/Source/_javascript_Core/runtime/MapDataInlines.h	2015-05-08 20:07:29 UTC (rev 184009)
@@ -91,15 +91,16 @@
 template <typename Map, typename Key>
 inline Entry* MapDataImpl<Entry, JSIterator>::add(ExecState* exec, JSCell* owner, Map& map, Key key, KeyType keyValue)
 {
-    typename Map::iterator location = map.find(key);
-    if (location != map.end())
-        return &m_entries[location->value];
+    auto result = map.add(key, m_size);
+    if (!result.isNewEntry)
+        return &m_entries[result.iterator->value];
 
-    if (!ensureSpaceForAppend(exec, owner))
+    if (!ensureSpaceForAppend(exec, owner)) {
+        map.remove(result.iterator);
         return 0;
+    }
 
-    auto result = map.add(key, m_size);
-    RELEASE_ASSERT(result.isNewEntry);
+    result.iterator->value = m_size;
     Entry* entry = &m_entries[m_size++];
     new (entry) Entry();
     entry->setKey(exec->vm(), owner, keyValue.value);
@@ -174,7 +175,9 @@
 {
     ASSERT(shouldPack());
     int32_t newEnd = 0;
-    RELEASE_ASSERT(newCapacity > 0);
+    ASSERT(newCapacity > 0);
+    RELEASE_ASSERT(newCapacity > m_size);
+
     for (int32_t i = 0; i < m_size; i++) {
         Entry& entry = m_entries[i];
         if (!entry.key()) {
@@ -194,14 +197,22 @@
     }
 
     // Fixup for the hashmaps
-    for (auto ptr = m_valueKeyedTable.begin(); ptr != m_valueKeyedTable.end(); ++ptr)
-        ptr->value = m_entries[ptr->value].key().get().asInt32();
-    for (auto ptr = m_cellKeyedTable.begin(); ptr != m_cellKeyedTable.end(); ++ptr)
-        ptr->value = m_entries[ptr->value].key().get().asInt32();
-    for (auto ptr = m_stringKeyedTable.begin(); ptr != m_stringKeyedTable.end(); ++ptr)
-        ptr->value = m_entries[ptr->value].key().get().asInt32();
-    for (auto ptr = m_symbolKeyedTable.begin(); ptr != m_symbolKeyedTable.end(); ++ptr)
-        ptr->value = m_entries[ptr->value].key().get().asInt32();
+    for (auto ptr = m_valueKeyedTable.begin(); ptr != m_valueKeyedTable.end(); ++ptr) {
+        if (ptr->value < m_size)
+            ptr->value = m_entries[ptr->value].key().get().asInt32();
+    }
+    for (auto ptr = m_cellKeyedTable.begin(); ptr != m_cellKeyedTable.end(); ++ptr) {
+        if (ptr->value < m_size)
+            ptr->value = m_entries[ptr->value].key().get().asInt32();
+    }
+    for (auto ptr = m_stringKeyedTable.begin(); ptr != m_stringKeyedTable.end(); ++ptr) {
+        if (ptr->value < m_size)
+            ptr->value = m_entries[ptr->value].key().get().asInt32();
+    }
+    for (auto ptr = m_symbolKeyedTable.begin(); ptr != m_symbolKeyedTable.end(); ++ptr) {
+        if (ptr->value < m_size)
+            ptr->value = m_entries[ptr->value].key().get().asInt32();
+    }
 
     ASSERT((m_size - newEnd) == m_deletedCount);
     m_deletedCount = 0;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to