Commit de24d1bb authored by verdre's avatar verdre

function: Only get function name if we actually warn

Getting the function name for logging a warning/error message using
format_function_name() is expensive and shows up with quite a few
percent in the profiler.

Luckily, we can completely get rid of that overhead by only getting the
function name in case we actually have to warn. To do that, check the
number of arguments ourselves instead of using args.requireAtLeast() and
then move the call to format_function_name() into the if-conditions of
those checks.
parent b4fb6809
......@@ -834,14 +834,18 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
*
* @args.length() is the number of arguments that were actually passed.
*/
GjsAutoChar name = format_function_name(function);
if (args.length() > function->expected_js_argc) {
GjsAutoChar name = format_function_name(function);
if (!JS::WarnUTF8(
context, "Too many arguments to %s: expected %d, got %u",
name.get(), function->expected_js_argc, args.length()))
return false;
} else if (!args.requireAtLeast(context, name,
function->expected_js_argc)) {
} else if (args.length() < function->expected_js_argc) {
GjsAutoChar name = format_function_name(function);
args.reportMoreArgsNeeded(context, name,
function->expected_js_argc, args.length());
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment