Skip to content
Permalink
Browse files
Use Vector::reserveInitialCapacity and Vector::uncheckedAppend for JS…
…C'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):


Canonical link: https://commits.webkit.org/132036@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@147349 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
BenjaminPoulain committed Apr 1, 2013
1 parent fec1934 commit 23df0dca6dac234f02145383fd746cf906f05181
Showing 5 changed files with 41 additions and 17 deletions.
@@ -73,10 +73,11 @@ static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec)

JSObjectCallAsConstructorCallback callback = jsCast<JSCallbackConstructor*>(constructor)->callback();
if (callback) {
int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
arguments[i] = toRef(exec, exec->argument(i));
size_t argumentCount = exec->argumentCount();
Vector<JSValueRef, 16> arguments;
arguments.reserveInitialCapacity(argumentCount);
for (size_t i = 0; i < argumentCount; ++i)
arguments.uncheckedAppend(toRef(exec, exec->argument(i)));

JSValueRef exception = 0;
JSObjectRef result;
@@ -69,10 +69,11 @@ EncodedJSValue JSCallbackFunction::call(ExecState* exec)
JSObjectRef functionRef = toRef(exec->callee());
JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));

int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
arguments[i] = toRef(exec, exec->argument(i));
size_t argumentCount = exec->argumentCount();
Vector<JSValueRef, 16> arguments;
arguments.reserveInitialCapacity(argumentCount);
for (size_t i = 0; i < argumentCount; ++i)
arguments.uncheckedAppend(toRef(exec, exec->argument(i)));

JSValueRef exception = 0;
JSValueRef result;
@@ -368,10 +368,11 @@ EncodedJSValue JSCallbackObject<Parent>::construct(ExecState* exec)

for (JSClassRef jsClass = jsCast<JSCallbackObject<Parent>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
arguments[i] = toRef(exec, exec->argument(i));
size_t argumentCount = exec->argumentCount();
Vector<JSValueRef, 16> arguments;
arguments.reserveInitialCapacity(argumentCount);
for (size_t i = 0; i < argumentCount; ++i)
arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
JSValueRef exception = 0;
JSObject* result;
{
@@ -434,10 +435,11 @@ EncodedJSValue JSCallbackObject<Parent>::call(ExecState* exec)

for (JSClassRef jsClass = jsCast<JSCallbackObject<Parent>*>(toJS(functionRef))->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
int argumentCount = static_cast<int>(exec->argumentCount());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
arguments[i] = toRef(exec, exec->argument(i));
size_t argumentCount = exec->argumentCount();
Vector<JSValueRef, 16> arguments;
arguments.reserveInitialCapacity(argumentCount);
for (size_t i = 0; i < argumentCount; ++i)
arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
JSValueRef exception = 0;
JSValue result;
{
@@ -551,7 +551,7 @@ JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef o
size_t size = array.size();
propertyNames->array.reserveInitialCapacity(size);
for (size_t i = 0; i < size; ++i)
propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].string()).leakRef()));
propertyNames->array.uncheckedAppend(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].string()).leakRef()));

return JSPropertyNameArrayRetain(propertyNames);
}
@@ -1,3 +1,23 @@
2013-04-01 Benjamin Poulain <benjamin@webkit.org>

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):

2013-04-01 Mark Hahnenberg <mhahnenberg@apple.com>

Fixing borked VS 2010 project file

0 comments on commit 23df0dc

Please sign in to comment.