JS speed - Konq vs. Mozilla
Koos Vriezen
koos.vriezen at xs4all.nl
Sat Sep 7 13:08:51 BST 2002
On Fri, 6 Sep 2002, David Faure wrote:
> Hmm, this one confuses me a bit. Can you add comments to the code? :}
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.
Still, I'm not sure why its faster. Maybe its the 'Collector::collect()'
that's faster in the next run (less blocks).
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 11:59:40
@@ -213,35 +213,68 @@ 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;
}
// delete the empty containers
- block = root;
+ if (nonfull)
+ block = nonfull;
currentBlock = 0L;
CollectorBlock *last = root;
while (block) {
More information about the kfm-devel
mailing list