Changeset 4156 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Apr 22, 2003, 5:09:32 PM (22 years ago)
Author:
mjs
Message:

Reviewed by Ken.

Improved List pool for 3% speed improvement on cvs-js-ibench

  • kjs/list.cpp: Replaced the roving cursor with a free list and raised the high water mark to 384.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/list.cpp

    r3373 r4156  
    2929
    3030// tunable parameters
    31 const int poolSize = 32; // must be a power of 2
     31const int poolSize = 384;
    3232const int inlineValuesSize = 4;
    3333
    34 // derived constants
    35 const int poolSizeMask = poolSize - 1;
    3634
    3735enum ListImpState { unusedInPool = 0, usedInPool, usedOnHeap, immortal };
     
    4442    ValueImp **overflow;
    4543
     44    ListImp *nextInFreeList;
     45
    4646#if DUMP_STATISTICS
    4747    int sizeHighWaterMark;
     
    5050
    5151static ListImp pool[poolSize];
    52 static int poolCursor;
     52static ListImp *poolFreeList;
     53static int poolUsed;
    5354
    5455#if DUMP_STATISTICS
     
    8990{
    9091    // Find a free one in the pool.
    91     int c = poolCursor;
    92     int i = c;
    93     do {
    94         ListImp *imp = &pool[i];
    95         ListImpState s = imp->state;
    96         i = (i + 1) & poolSizeMask;
    97         if (s == unusedInPool) {
    98             poolCursor = i;
    99             imp->state = usedInPool;
    100             return imp;
    101         }
    102     } while (i != c);
     92    if (poolUsed < poolSize) {
     93        ListImp *imp = poolFreeList ? poolFreeList : &pool[0];
     94        poolFreeList = imp->nextInFreeList ? imp->nextInFreeList : imp + 1;
     95        imp->state = usedInPool;
     96        poolUsed++;
     97        return imp;
     98    }
    10399   
    104100    ListImp *imp = new ListImp;
     
    109105static inline void deallocateListImp(ListImp *imp)
    110106{
    111     if (imp->state == usedInPool)
     107    if (imp->state == usedInPool) {
    112108        imp->state = unusedInPool;
    113     else
     109        imp->nextInFreeList = poolFreeList;
     110        poolFreeList = imp;
     111        poolUsed--;
     112    } else {
    114113        delete imp;
     114    }
    115115}
    116116
Note: See TracChangeset for help on using the changeset viewer.