[gjs] Replace remaining get_property with interned jsids



commit 9cea91babcdd0d2d880a86f76dab68738967f647
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Apr 8 21:36:30 2013 +0200

    Replace remaining get_property with interned jsids
    
    None of these are hot paths, but it helps anyway.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697592

 gjs/importer.c |   36 +++++++++++++++++++++---------------
 gjs/native.c   |    6 +++++-
 2 files changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/gjs/importer.c b/gjs/importer.c
index 52b8719..577609b 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -29,11 +29,11 @@
 #include <gjs/gjs-module.h>
 #include <gjs/importer.h>
 #include <gjs/compat.h>
+#include <gjs/runtime.h>
 
 #include <string.h>
 
-#define MODULE_INIT_PROPERTY "__init__"
-#define MODULE_INIT_FILENAME MODULE_INIT_PROPERTY".js"
+#define MODULE_INIT_FILENAME "__init__.js"
 
 static char **gjs_search_path = NULL;
 
@@ -282,15 +282,19 @@ load_module_init(JSContext  *context,
     jsval script_retval;
     JSObject *module_obj;
     GError *error;
+    JSBool found;
+    jsid module_init_name;
 
     /* First we check if js module has already been loaded  */
-    if (gjs_object_has_property(context, in_object, MODULE_INIT_PROPERTY)) {
+    module_init_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
+                                                    GJS_STRING_MODULE_INIT);
+    if (JS_HasPropertyById(context, in_object, module_init_name, &found) && found) {
         jsval module_obj_val;
 
-        if (gjs_object_get_property(context,
-                                    in_object,
-                                    MODULE_INIT_PROPERTY,
-                                    &module_obj_val)) {
+        if (JS_GetPropertyById(context,
+                               in_object,
+                               module_init_name,
+                               &module_obj_val)) {
             return JSVAL_TO_OBJECT(module_obj_val);
         }
     }
@@ -307,10 +311,10 @@ load_module_init(JSContext  *context,
 
     /* Define module in importer for future use and to avoid module_obj
      * object to be garbage collected during the evaluation of the script */
-    JS_DefineProperty(context, in_object,
-                      MODULE_INIT_PROPERTY, OBJECT_TO_JSVAL(module_obj),
-                      NULL, NULL,
-                      GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT);
+    JS_DefinePropertyById(context, in_object,
+                          module_init_name, OBJECT_TO_JSVAL(module_obj),
+                          NULL, NULL,
+                          GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT);
 
     script_len = 0;
     error = NULL;
@@ -503,10 +507,6 @@ do_import(JSContext  *context,
     JSBool result;
     GPtrArray *directories;
 
-    if (strcmp(name, MODULE_INIT_PROPERTY) == 0) {
-        return JS_FALSE;
-    }
-
     if (!gjs_object_require_property(context, obj, "importer", "searchPath", &search_path_val)) {
         return JS_FALSE;
     }
@@ -925,9 +925,15 @@ importer_new_resolve(JSContext *context,
     Importer *priv;
     char *name;
     JSBool ret = JS_TRUE;
+    jsid module_init_name;
 
     *objp = NULL;
 
+    module_init_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
+                                                    GJS_STRING_MODULE_INIT);
+    if (*id == module_init_name)
+        return JS_TRUE;
+
     if (!gjs_get_string_id(context, *id, &name))
         return JS_FALSE;
 
diff --git a/gjs/native.c b/gjs/native.c
index b62a103..01d836d 100644
--- a/gjs/native.c
+++ b/gjs/native.c
@@ -30,6 +30,7 @@
 #include "native.h"
 #include "compat.h"
 #include "jsapi-util.h"
+#include "runtime.h"
 
 typedef struct {
     GjsDefineModuleFunc func;
@@ -80,8 +81,11 @@ module_get_parent(JSContext *context,
                   JSObject  *module_obj)
 {
     jsval value;
+    jsid parent_module_name;
 
-    if (gjs_object_get_property(context, module_obj, "__parentModule__", &value) &&
+    parent_module_name = gjs_runtime_get_const_string(JS_GetRuntime(context),
+                                                      GJS_STRING_PARENT_MODULE);
+    if (JS_GetPropertyById(context, module_obj, parent_module_name, &value) &&
         !JSVAL_IS_NULL(value) &&
         JSVAL_IS_OBJECT(value)) {
         return JSVAL_TO_OBJECT(value);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]