JS speed - Konq vs. Mozilla

Koos Vriezen koos.vriezen at xs4all.nl
Sat Sep 7 13:54:17 BST 2002


On Sat, 7 Sep 2002, Koos Vriezen wrote:

> Ok, this patch has some comments added. Also added a 'moved' variable, so
> that 'Collector::collect()' doesn't return 'true' in case only slots are
> moved.

Oops, the patch has a leftover from a test (filling empty blocks as well
and starting last scan with nonfull).
Fixed in this patch.

Koos
-------------- next part --------------
Index: collector.cpp
===================================================================
RCS file: /home/kde/kdelibs/kjs/collector.cpp,v
retrieving revision 1.34
diff -u -3 -p -r1.34 collector.cpp
--- collector.cpp	2002/09/05 15:51:38	1.34
+++ collector.cpp	2002/09/07 12:49:59
@@ -213,29 +213,61 @@ bool Collector::collect()
 
   // 2nd step: free memory
   block = root;
+  CollectorBlock *nonfull = 0L;
   while (block) {
     ValueImp **r = block->mem;
     int freespot = block->filled;
     bool firstfreeset = false;
     int del = 0;
+    int moved = 0;
     for (int i = 0; i < block->filled; i++, r++) {
       ValueImp *imp = (*r);
       if ((imp->_flags & ValueImp::VI_DESTRUCTED) != 0) {
+        // free this slot
         free(imp);
         del++;
         if (!firstfreeset) {
+          // found the first free slot in this block (slot deleted)
           firstfreeset = true;
           freespot = r - block->mem;
         }
+      } else if (nonfull) {
+        // move this slot to nonfull
+        nonfull->mem[nonfull->filled] = imp;
+        nonfull->filled++;
+        moved++;
+        while (nonfull && 
+               (nonfull->filled == nonfull->size || nonfull->filled == 0)) {
+          // 'nonfull' is full or empty, go next
+          nonfull = nonfull->next;
+          if (nonfull == block)
+            nonfull = 0L;
+        }
+        if (!firstfreeset) {
+          // found the first free slot in this block (slot moved)
+          firstfreeset = true;
+          freespot = r - block->mem;
+        }
       } else if (firstfreeset) {
-         *(block->mem + freespot) = imp;
-         freespot++;
+        // move this slot to freespot in this block 
+        block->mem[freespot] = imp;
+        freespot++;
       }
     }
     filled -= del;
-    block->filled -= del;
+    block->filled -= (del + moved);
     assert(freespot == block->filled);
+    if (!nonfull)
+      nonfull = block;
     block = block->next;
+    while (nonfull && 
+           (nonfull->filled == nonfull->size || nonfull->filled == 0)) {
+      // 'nonfull' is full or empty, go next
+      nonfull = nonfull->next;
+      if (nonfull == block)
+        nonfull = 0L;
+    }
+
     if (del)
       deleted = true;
   }


More information about the kfm-devel mailing list