[gjs: 7/10] js: Compare jsid in some resolve hooks instead of strings



commit 74693dfc2ba5e6430e896a053780b9ba9274f624
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Sep 5 21:07:07 2018 -0400

    js: Compare jsid in some resolve hooks instead of strings
    
    It's faster to compare jsids because they can compare directly by value.
    Now that we atomize common strings, we can do this in the resolve hooks
    of Ns, Repo, and Importer.

 gi/ns.cpp        |  5 ++---
 gi/repo.cpp      |  5 ++---
 gjs/atoms.h      |  1 +
 gjs/importer.cpp | 11 ++---------
 4 files changed, 7 insertions(+), 15 deletions(-)
---
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 505b00cd..5fc0012d 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -61,9 +61,8 @@ ns_resolve(JSContext       *context,
     }
 
     /* let Object.prototype resolve these */
-    JSFlatString *str = JSID_TO_FLAT_STRING(id);
-    if (JS_FlatStringEqualsAscii(str, "valueOf") ||
-        JS_FlatStringEqualsAscii(str, "toString")) {
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    if (id == atoms.to_string() || id == atoms.value_of()) {
         *resolved = false;
         return true;
     }
diff --git a/gi/repo.cpp b/gi/repo.cpp
index 98aa3dbb..e5284000 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -171,10 +171,9 @@ repo_resolve(JSContext       *context,
         return true; /* not resolved, but no error */
     }
 
-    JSFlatString *str = JSID_TO_FLAT_STRING(id);
     /* let Object.prototype resolve these */
-    if (JS_FlatStringEqualsAscii(str, "valueOf") ||
-        JS_FlatStringEqualsAscii(str, "toString")) {
+    const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
+    if (id == atoms.to_string() || id == atoms.value_of()) {
         *resolved = false;
         return true;
     }
diff --git a/gjs/atoms.h b/gjs/atoms.h
index 69ef49ba..4c8ae52c 100644
--- a/gjs/atoms.h
+++ b/gjs/atoms.h
@@ -61,6 +61,7 @@
     macro(search_path, "searchPath") \
     macro(stack, "stack") \
     macro(to_string, "toString") \
+    macro(value_of, "valueOf") \
     macro(version, "version") \
     macro(versions, "versions") \
     macro(width, "width") \
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 3d3c2c48..9b315821 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -750,15 +750,8 @@ importer_resolve(JSContext        *context,
     }
 
     const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
-    if (id == atoms.module_init()) {
-        *resolved = false;
-        return true;
-    }
-
-    /* let Object.prototype resolve these */
-    JSFlatString *str = JSID_TO_FLAT_STRING(id);
-    if (JS_FlatStringEqualsAscii(str, "valueOf") ||
-        JS_FlatStringEqualsAscii(str, "toString")) {
+    if (id == atoms.module_init() || id == atoms.to_string() ||
+        id == atoms.value_of()) {
         *resolved = false;
         return true;
     }


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