[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:45:48 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 620ab41d4e51f6b934b9791084909ffae588287d
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jun 20 21:49:17 2003 +0000

            Reviewed by Maciej.
    
            - improved the property map sorting technique so that the indices
              are separate for each property map, and also preserve the ordering
              when property maps are saved and restored
    
            * kjs/property_map.cpp:
            (PropertyMap::put): Don't bother setting the index for _singleEntry, since there's
            no need to sort a single entry. Use the per-table lastIndexUsed instead of a global.
            (PropertyMap::expand): Don't use the index (uninitialized now) out of a _singleEntry
            when putting it in a newly-created map; just use 0. Compute a value for the new map's
            lastIndexUsed as we walk through the elements we are adding to it (using the same old
            indices from the old map).
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4562 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index b6d689e..e303120 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,19 @@
+2003-06-20  Darin Adler  <darin at apple.com>
+
+        Reviewed by Maciej.
+
+        - improved the property map sorting technique so that the indices
+          are separate for each property map, and also preserve the ordering
+          when property maps are saved and restored
+
+        * kjs/property_map.cpp:
+        (PropertyMap::put): Don't bother setting the index for _singleEntry, since there's
+        no need to sort a single entry. Use the per-table lastIndexUsed instead of a global.
+        (PropertyMap::expand): Don't use the index (uninitialized now) out of a _singleEntry
+        when putting it in a newly-created map; just use 0. Compute a value for the new map's
+        lastIndexUsed as we walk through the elements we are adding to it (using the same old
+        indices from the old map).
+
 === Safari-85.1 ===
 
 === Safari-85 ===
diff --git a/JavaScriptCore/ChangeLog-2003-10-25 b/JavaScriptCore/ChangeLog-2003-10-25
index b6d689e..e303120 100644
--- a/JavaScriptCore/ChangeLog-2003-10-25
+++ b/JavaScriptCore/ChangeLog-2003-10-25
@@ -1,3 +1,19 @@
+2003-06-20  Darin Adler  <darin at apple.com>
+
+        Reviewed by Maciej.
+
+        - improved the property map sorting technique so that the indices
+          are separate for each property map, and also preserve the ordering
+          when property maps are saved and restored
+
+        * kjs/property_map.cpp:
+        (PropertyMap::put): Don't bother setting the index for _singleEntry, since there's
+        no need to sort a single entry. Use the per-table lastIndexUsed instead of a global.
+        (PropertyMap::expand): Don't use the index (uninitialized now) out of a _singleEntry
+        when putting it in a newly-created map; just use 0. Compute a value for the new map's
+        lastIndexUsed as we walk through the elements we are adding to it (using the same old
+        indices from the old map).
+
 === Safari-85.1 ===
 
 === Safari-85 ===
diff --git a/JavaScriptCore/kjs/property_map.cpp b/JavaScriptCore/kjs/property_map.cpp
index bf58523..5fb2c0f 100644
--- a/JavaScriptCore/kjs/property_map.cpp
+++ b/JavaScriptCore/kjs/property_map.cpp
@@ -32,6 +32,8 @@
 // At the time I added USE_SINGLE_ENTRY, the optimization still gave a 1.5%
 // performance boost to the iBench JavaScript benchmark so I didn't remove it.
 
+// FIXME: _singleEntry.index is unused.
+
 #if !DO_CONSISTENCY_CHECK
 #define checkConsistency() ((void)0)
 #endif
@@ -42,12 +44,6 @@ namespace KJS {
 // but it's not going to blow out the stack to allocate this number of pointers.
 const int smallMapThreshold = 1024;
 
-// Ever-increasing index used to identify the order items were inserted into
-// the property map. It's vital that addEnumerablesToReferenceList return
-// the properties in the order they were added for compatibility with other
-// browsers' JavaScript implementations.
-static int lastIndexUsed;
-
 #if DUMP_STATISTICS
 
 static int numProbes;
@@ -70,11 +66,16 @@ PropertyMapStatisticsExitLogger::~PropertyMapStatisticsExitLogger()
 
 #endif
 
+// lastIndexUsed is an ever-increasing index used to identify the order items
+// were inserted into the property map. It's vital that addEnumerablesToReferenceList
+// return the properties in the order they were added for compatibility with other
+// browsers' JavaScript implementations.
 struct PropertyMapHashTable
 {
     int sizeMask;
     int size;
     int keyCount;
+    int lastIndexUsed;
     PropertyMapHashTableEntry entries[1];
 };
 
@@ -262,7 +263,6 @@ void PropertyMap::put(const Identifier &name, ValueImp *value, int attributes)
             _singleEntry.key = rep;
             _singleEntry.value = value;
             _singleEntry.attributes = attributes;
-            _singleEntry.index = ++lastIndexUsed;
             checkConsistency();
             return;
         }
@@ -304,7 +304,7 @@ void PropertyMap::put(const Identifier &name, ValueImp *value, int attributes)
     _table->entries[i].key = rep;
     _table->entries[i].value = value;
     _table->entries[i].attributes = attributes;
-    _table->entries[i].index = ++lastIndexUsed;
+    _table->entries[i].index = ++_table->lastIndexUsed;
     ++_table->keyCount;
 
     checkConsistency();
@@ -354,7 +354,7 @@ void PropertyMap::expand()
 #if USE_SINGLE_ENTRY
     UString::Rep *key = _singleEntry.key;
     if (key) {
-        insert(key, _singleEntry.value, _singleEntry.attributes, _singleEntry.index);
+        insert(key, _singleEntry.value, _singleEntry.attributes, 0);
         _singleEntry.key = 0;
 	// update the count, because single entries don't count towards
 	// the table key count
@@ -363,17 +363,22 @@ void PropertyMap::expand()
     }
 #endif
     
+    int lastIndexUsed = 0;
     for (int i = 0; i != oldTableSize; ++i) {
-        UString::Rep *key = oldTable->entries[i].key;
+        Entry &entry = oldTable->entries[i];
+        UString::Rep *key = entry.key;
         if (key) {
             // Don't copy deleted-element sentinels.
             if (key == &UString::Rep::null)
                 key->deref();
-            else
-                insert(key, oldTable->entries[i].value,
-                    oldTable->entries[i].attributes, oldTable->entries[i].index);
+            else {
+                int index = entry.index;
+                lastIndexUsed = MAX(index, lastIndexUsed);
+                insert(key, entry.value, entry.attributes, index);
+            }
         }
     }
+    _table->lastIndexUsed = lastIndexUsed;
 
     free(oldTable);
 
@@ -582,14 +587,42 @@ void PropertyMap::save(SavedProperties &p) const
         }
 #endif
     } else {
+        // Save in the right order so we don't lose the order.
+        // Another possibility would be to save the indices.
+
+        // Allocate a buffer to use to sort the keys.
+        Entry *fixedSizeBuffer[smallMapThreshold];
+        Entry **sortedEntries;
+        if (count <= smallMapThreshold)
+            sortedEntries = fixedSizeBuffer;
+        else
+            sortedEntries = new Entry *[count];
+
+        // Get pointers to the entries in the buffer.
+        Entry **p = sortedEntries;
         for (int i = 0; i != _table->size; ++i) {
-            if (_table->entries[i].key && !(_table->entries[i].attributes & (ReadOnly | DontEnum | Function))) {
-                prop->key = Identifier(_table->entries[i].key);
-                prop->value = Value(_table->entries[i].value);
-                prop->attributes = _table->entries[i].attributes;
-                ++prop;
-            }
+            Entry *e = &_table->entries[i];
+            if (e->key && !(e->attributes & (ReadOnly | DontEnum | Function)))
+                *p++ = e;
+        }
+        assert(p - sortedEntries == count);
+
+        // Sort the entries by index.
+        qsort(sortedEntries, p - sortedEntries, sizeof(sortedEntries[0]), comparePropertyMapEntryIndices);
+
+        // Put the sorted entries into the saved properties list.
+        Entry **q = sortedEntries;
+        while (q != p) {
+            Entry *e = *q++;
+            prop->key = Identifier(e->key);
+            prop->value = Value(e->value);
+            prop->attributes = e->attributes;
+            ++prop;
         }
+
+        // Deallocate the buffer.
+        if (sortedEntries != fixedSizeBuffer)
+            delete [] sortedEntries;
     }
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list