[gjs/march-maintenance: 8/11] object: Return early from property resolve if name starts with -
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/march-maintenance: 8/11] object: Return early from property resolve if name starts with -
- Date: Tue, 31 Mar 2020 04:47:50 +0000 (UTC)
commit 047f250c820bd305fefc837ce4b5cc3b7ac62649
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Mar 11 22:49:18 2020 -0700
object: Return early from property resolve if name starts with -
This is a small optimization. GObject property names must start with a
letter. Any other character gets turned into a dash by
canonicalize_name(), so if the property name starts with a dash after
canonicalization then it's not a valid property name and can't be a
GObject property, so we can return early from any code that is checking
whether it is or not.
I noticed that resolve was checking for _init and _instance_init, so
this seems like a pretty common case to optimize for.
gi/object.cpp | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 96e2062a..2259886e 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -667,8 +667,11 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj,
GjsAutoChar canonical_name;
if (resolve_props == ConsiderMethodsAndProperties) {
- canonical_name = gjs_hyphen_from_camel(name);
- canonicalize_key(canonical_name);
+ // Optimization: GObject property names must start with a letter
+ if (g_ascii_isalpha(name[0])) {
+ canonical_name = gjs_hyphen_from_camel(name);
+ canonicalize_key(canonical_name);
+ }
}
GIInterfaceInfo** interfaces;
@@ -710,7 +713,7 @@ bool ObjectPrototype::resolve_no_info(JSContext* cx, JS::HandleObject obj,
}
}
- if (resolve_props == ConsiderOnlyMethods)
+ if (!canonical_name)
continue;
/* If the name refers to a GObject property, lazily define the property
@@ -729,6 +732,10 @@ static bool
is_gobject_property_name(GIObjectInfo *info,
const char *name)
{
+ // Optimization: GObject property names must start with a letter
+ if (!g_ascii_isalpha(name[0]))
+ return false;
+
int n_props = g_object_info_get_n_properties(info);
int n_ifaces = g_object_info_get_n_interfaces(info);
int ix;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]