Browse files

[Perf] Avoid calling func_get_args() for functions with no explicit p…

…arams

Summary: In the case of calling func_get_args() inside a function with no
explicit params, avoid actually invoking func_get_args() and just use the
passed in params array as the result.

Task ID: #518270

Blame Rev:

Reviewers: qigao

CC:

Test Plan: slow_tests

Revert Plan:

Tags:

- begin *PUBLIC* platform impact section -
Bugzilla: #
- end platform impact -

Differential Revision: 251308
  • Loading branch information...
1 parent d960f1f commit 6679c945700399ac30b1136bacf305a5fd553095 @stephentu stephentu committed with scottmac May 14, 2011
Showing with 24 additions and 4 deletions.
  1. +11 −3 src/compiler/analysis/function_scope.cpp
  2. +13 −1 src/compiler/expression/simple_function_call.cpp
View
14 src/compiler/analysis/function_scope.cpp
@@ -1357,9 +1357,17 @@ void FunctionScope::outputCPPDynamicInvoke(CodeGenerator &cg,
extra = ", p";
}
} else {
- cg_printf("const Array &p(count > %d ? "
- "params.slice(%d, count - %d, false) : Array());\n",
- m_maxParam, m_maxParam, m_maxParam);
+ if (m_maxParam) {
+ cg_printf("const Array &p(count > %d ? "
+ "params.slice(%d, count - %d, false) : Array());\n",
+ m_maxParam, m_maxParam, m_maxParam);
+ } else {
+ // in this case, avoid the un-necessary call to params.slice(),
+ // since we want the entire params array anyways
+ ASSERT(m_maxParam == 0);
+ cg_printf("const Array &p(count > 0 ? "
+ "params : Array());\n");
+ }
extra = ", p";
}
}
View
14 src/compiler/expression/simple_function_call.cpp
@@ -1797,8 +1797,8 @@ void SimpleFunctionCall::outputCPPImpl(CodeGenerator &cg,
{
FunctionScopePtr func = getFunctionScope();
if (func) {
+ bool isGetArgs = m_name == "func_get_args";
if (func->isGenerator()) {
- bool isGetArgs = m_name == "func_get_args";
cg_printf("%s%s.%sinvoke(\"%s\", ",
Option::VariablePrefix, CONTINUATION_OBJECT_NAME,
Option::ObjectPrefix,
@@ -1815,6 +1815,18 @@ void SimpleFunctionCall::outputCPPImpl(CodeGenerator &cg,
cg_printf(".create()))%s", isGetArgs ? ".toArray()" : "");
return;
}
+ if (isGetArgs && func->getMaxParamCount() == 0) {
+ // in the special case of calling func_get_args() for
+ // a function with no explicit params, bypass the call
+ // to func_get_args() and simply use the passed in args
+ // array or the empty array
+ if (func->isVariableArgument()) {
+ cg_printf("args.isNull() ? Array::Create() : args");
+ } else {
+ cg_printf("Array::Create()");
+ }
+ return;
+ }
cg_printf("%s(", m_name.c_str());
func->outputCPPParamsCall(cg, ar, true);
if (m_params) {

0 comments on commit 6679c94

Please sign in to comment.