Ignore:
Timestamp:
Nov 18, 2002, 2:49:26 PM (23 years ago)
Author:
darin
Message:
  • simplified the ExecState class, which was showing up in profiles

Sped up JavaScript iBench by 6%.

  • kjs/interpreter.h: Removed the level of indirection, and made it all inline.
  • kjs/interpreter.cpp: Removed ExecState implementation from here altogether.
  • fixed an oversight in my sort speedup
  • kjs/array_object.h: Add pushUndefinedObjectsToEnd.
  • kjs/array_object.cpp: (ArrayInstanceImp::sort): Call pushUndefinedObjectsToEnd. (ArrayInstanceImp::pushUndefinedObjectsToEnd): Added. Pushes all undefined to the end of the array.
File:
1 edited

Legend:

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

    r2736 r2738  
    203203void ArrayInstanceImp::sort(ExecState *exec)
    204204{
     205    int lengthNotIncludingUndefined = pushUndefinedObjectsToEnd();
     206   
    205207    execForCompareByStringForQSort = exec;
    206     qsort(storage, length, sizeof(ValueImp *), compareByStringForQSort);
     208    qsort(storage, lengthNotIncludingUndefined, sizeof(ValueImp *), compareByStringForQSort);
    207209    execForCompareByStringForQSort = 0;
    208210}
     
    236238void ArrayInstanceImp::sort(ExecState *exec, Object &compareFunction)
    237239{
     240    int lengthNotIncludingUndefined = pushUndefinedObjectsToEnd();
     241   
    238242    CompareWithCompareFunctionArguments args(exec, compareFunction.imp());
    239243    compareWithCompareFunctionArguments = &args;
    240     qsort(storage, length, sizeof(ValueImp *), compareWithCompareFunctionForQSort);
     244    qsort(storage, lengthNotIncludingUndefined, sizeof(ValueImp *), compareWithCompareFunctionForQSort);
    241245    compareWithCompareFunctionArguments = 0;
     246}
     247
     248unsigned ArrayInstanceImp::pushUndefinedObjectsToEnd()
     249{
     250    ValueImp *undefined = UndefinedImp::staticUndefined;
     251
     252    unsigned o = 0;
     253    for (unsigned i = 0; i != length; ++i) {
     254        ValueImp *v = storage[i];
     255        if (v && v != undefined) {
     256            if (o != i)
     257                storage[o] = v;
     258            o++;
     259        }
     260    }
     261    if (o != length)
     262        memset(storage + o, 0, sizeof(ValueImp *) * (length - o));
     263    return o;
    242264}
    243265
Note: See TracChangeset for help on using the changeset viewer.