[gjs] KeepAlive: use an interned jsid for keep alive name
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] KeepAlive: use an interned jsid for keep alive name
- Date: Tue, 23 Apr 2013 20:54:35 +0000 (UTC)
commit 915ac72bcfb983cc3491242b60580f40178ef943
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Mon Apr 8 20:11:06 2013 +0200
KeepAlive: use an interned jsid for keep alive name
The keep alive object is accessed very often, so it definitely
benefits from using an already interned jsid instead of converting
and hashing the same string again and again.
https://bugzilla.gnome.org/show_bug.cgi?id=697592
gi/keep-alive.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/gi/keep-alive.c b/gi/keep-alive.c
index a8eea22..05c7ff1 100644
--- a/gi/keep-alive.c
+++ b/gi/keep-alive.c
@@ -27,6 +27,7 @@
#include <gjs/gjs-module.h>
#include <gjs/compat.h>
+#include <gjs/runtime.h>
#include <util/log.h>
#include <util/glib.h>
@@ -319,15 +320,17 @@ gjs_keep_alive_remove_child(JSContext *context,
&child);
}
-#define GLOBAL_KEEP_ALIVE_NAME "__gc_this_on_context_destroy"
-
static JSObject*
gjs_keep_alive_get_from_parent(JSContext *context,
JSObject *parent)
{
+ jsid keep_alive_name;
jsval value;
- gjs_object_get_property(context, parent, GLOBAL_KEEP_ALIVE_NAME, &value);
+ keep_alive_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
+ GJS_STRING_KEEP_ALIVE_MARKER);
+ if (!JS_GetPropertyById(context, parent, keep_alive_name, &value))
+ return NULL;
if (JSVAL_IS_OBJECT(value))
return JSVAL_TO_OBJECT(value);
@@ -347,19 +350,22 @@ gjs_keep_alive_create_in_parent(JSContext *context,
JSObject *parent)
{
JSObject *keep_alive;
+ jsid keep_alive_name;
JS_BeginRequest(context);
keep_alive = gjs_keep_alive_new(context);
- if (!JS_DefineProperty(context, parent,
- GLOBAL_KEEP_ALIVE_NAME,
- OBJECT_TO_JSVAL(keep_alive),
- NULL, NULL,
- /* No ENUMERATE since this is a hidden
- * implementation detail kind of property
- */
- JSPROP_READONLY | JSPROP_PERMANENT))
+ keep_alive_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
+ GJS_STRING_KEEP_ALIVE_MARKER);
+ if (!JS_DefinePropertyById(context, parent,
+ keep_alive_name,
+ OBJECT_TO_JSVAL(keep_alive),
+ NULL, NULL,
+ /* No ENUMERATE since this is a hidden
+ * implementation detail kind of property
+ */
+ JSPROP_READONLY | JSPROP_PERMANENT))
gjs_fatal("no memory to define keep_alive property");
JS_EndRequest(context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]