Changeset 147349 in webkit


Ignore:
Timestamp:
Apr 1, 2013 12:39:14 PM (11 years ago)
Author:
benjamin@webkit.org
Message:

Use Vector::reserveInitialCapacity and Vector::uncheckedAppend for JSC's APIs
https://bugs.webkit.org/show_bug.cgi?id=113651

Reviewed by Andreas Kling.

This removes a bunch of branches on initialization and when
filling the vector.

  • API/JSCallbackConstructor.cpp:

(JSC::constructJSCallback):

  • API/JSCallbackFunction.cpp:

(JSC::JSCallbackFunction::call):

  • API/JSCallbackObjectFunctions.h:

(JSC::::construct):
(JSC::::call):

  • API/JSObjectRef.cpp:

(JSObjectCopyPropertyNames):

Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackConstructor.cpp

    r139541 r147349  
    7474    JSObjectCallAsConstructorCallback callback = jsCast<JSCallbackConstructor*>(constructor)->callback();
    7575    if (callback) {
    76         int argumentCount = static_cast<int>(exec->argumentCount());
    77         Vector<JSValueRef, 16> arguments(argumentCount);
    78         for (int i = 0; i < argumentCount; i++)
    79             arguments[i] = toRef(exec, exec->argument(i));
     76        size_t argumentCount = exec->argumentCount();
     77        Vector<JSValueRef, 16> arguments;
     78        arguments.reserveInitialCapacity(argumentCount);
     79        for (size_t i = 0; i < argumentCount; ++i)
     80            arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
    8081
    8182        JSValueRef exception = 0;
  • trunk/Source/JavaScriptCore/API/JSCallbackFunction.cpp

    r145848 r147349  
    7070    JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));
    7171
    72     int argumentCount = static_cast<int>(exec->argumentCount());
    73     Vector<JSValueRef, 16> arguments(argumentCount);
    74     for (int i = 0; i < argumentCount; i++)
    75         arguments[i] = toRef(exec, exec->argument(i));
     72    size_t argumentCount = exec->argumentCount();
     73    Vector<JSValueRef, 16> arguments;
     74    arguments.reserveInitialCapacity(argumentCount);
     75    for (size_t i = 0; i < argumentCount; ++i)
     76        arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
    7677
    7778    JSValueRef exception = 0;
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r140594 r147349  
    369369    for (JSClassRef jsClass = jsCast<JSCallbackObject<Parent>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
    370370        if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
    371             int argumentCount = static_cast<int>(exec->argumentCount());
    372             Vector<JSValueRef, 16> arguments(argumentCount);
    373             for (int i = 0; i < argumentCount; i++)
    374                 arguments[i] = toRef(exec, exec->argument(i));
     371            size_t argumentCount = exec->argumentCount();
     372            Vector<JSValueRef, 16> arguments;
     373            arguments.reserveInitialCapacity(argumentCount);
     374            for (size_t i = 0; i < argumentCount; ++i)
     375                arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
    375376            JSValueRef exception = 0;
    376377            JSObject* result;
     
    435436    for (JSClassRef jsClass = jsCast<JSCallbackObject<Parent>*>(toJS(functionRef))->classRef(); jsClass; jsClass = jsClass->parentClass) {
    436437        if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
    437             int argumentCount = static_cast<int>(exec->argumentCount());
    438             Vector<JSValueRef, 16> arguments(argumentCount);
    439             for (int i = 0; i < argumentCount; i++)
    440                 arguments[i] = toRef(exec, exec->argument(i));
     438            size_t argumentCount = exec->argumentCount();
     439            Vector<JSValueRef, 16> arguments;
     440            arguments.reserveInitialCapacity(argumentCount);
     441            for (size_t i = 0; i < argumentCount; ++i)
     442                arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
    441443            JSValueRef exception = 0;
    442444            JSValue result;
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r146494 r147349  
    552552    propertyNames->array.reserveInitialCapacity(size);
    553553    for (size_t i = 0; i < size; ++i)
    554         propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].string()).leakRef()));
     554        propertyNames->array.uncheckedAppend(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].string()).leakRef()));
    555555   
    556556    return JSPropertyNameArrayRetain(propertyNames);
  • trunk/Source/JavaScriptCore/ChangeLog

    r147335 r147349  
     12013-04-01  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Use Vector::reserveInitialCapacity and Vector::uncheckedAppend for JSC's APIs
     4        https://bugs.webkit.org/show_bug.cgi?id=113651
     5
     6        Reviewed by Andreas Kling.
     7
     8        This removes a bunch of branches on initialization and when
     9        filling the vector.
     10
     11        * API/JSCallbackConstructor.cpp:
     12        (JSC::constructJSCallback):
     13        * API/JSCallbackFunction.cpp:
     14        (JSC::JSCallbackFunction::call):
     15        * API/JSCallbackObjectFunctions.h:
     16        (JSC::::construct):
     17        (JSC::::call):
     18        * API/JSObjectRef.cpp:
     19        (JSObjectCopyPropertyNames):
     20
    1212013-04-01  Mark Hahnenberg  <mhahnenberg@apple.com>
    222
Note: See TracChangeset for help on using the changeset viewer.