[gjs/mozjs78: 3/21] function: Only get function name if we actually warn
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/mozjs78: 3/21] function: Only get function name if we actually warn
- Date: Sun, 5 Jul 2020 03:35:24 +0000 (UTC)
commit 9c70519719aac2822030703543ba2bc45c973ebf
Author: Jonas Dreßler <verdre v0yd nl>
Date: Fri Jun 26 23:03:20 2020 +0200
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.
gi/function.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 19594529..15f14caa 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]