[gjs] build: Use 'always inline' macro in more places



commit c1b352a6e823719951cdaaebb78dbcd84bad4eb9
Author: Philip Chimento <philip endlessm com>
Date:   Thu Jul 13 10:31:10 2017 -0700

    build: Use 'always inline' macro in more places
    
    On GCC 4.9, the inliner heuristic starts to complain again, because
    SpiderMonkey 52 includes more 'always inline' functions, so when we add
    ours in there, the inliner decides that functions are growing too much in
    size due to inlined code.
    
    Add a GJS_ALWAYS_INLINE macro just like Mozilla does in their code, and
    use it for our templated code and other boilerplate.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785040

 gjs/jsapi-class.h     |    4 +++-
 gjs/jsapi-util-args.h |   29 ++++++++++++-----------------
 gjs/jsapi-util.h      |    6 ++++++
 3 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/gjs/jsapi-class.h b/gjs/jsapi-class.h
index 29c44be..508c828 100644
--- a/gjs/jsapi-class.h
+++ b/gjs/jsapi-class.h
@@ -69,13 +69,15 @@ JSObject *gjs_construct_object_dynamic(JSContext                  *cx,
  *                              do_base_typecheck and priv_from_js
  */
 #define GJS_DEFINE_PRIV_FROM_JS(type, klass)                          \
-    G_GNUC_UNUSED static inline bool                                    \
+    GJS_ALWAYS_INLINE G_GNUC_UNUSED                                     \
+    static inline bool                                                  \
     do_base_typecheck(JSContext       *context,                         \
                       JS::HandleObject object,                          \
                       bool             throw_error)                     \
     {                                                                   \
         return gjs_typecheck_instance(context, object, &klass, throw_error);  \
     }                                                                   \
+    GJS_ALWAYS_INLINE                                                   \
     static inline type *                                                \
     priv_from_js(JSContext       *context,                              \
                  JS::HandleObject object)                               \
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 1fb3ec7..d0baa12 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -30,13 +30,7 @@
 #include "jsapi-util.h"
 #include "jsapi-wrapper.h"
 
-#ifdef __GNUC__
-#define GNUC_ALWAYS_INLINE __attribute__((always_inline))
-#else
-#define GNUC_ALWAYS_INLINE
-#endif
-
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline bool
 check_nullable(const char*& fchar,
                const char*& fmt_string)
@@ -53,7 +47,7 @@ check_nullable(const char*& fchar,
 
 /* This preserves the previous behaviour of gjs_parse_args(), but maybe we want
  * to use JS::ToBoolean instead? */
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -72,7 +66,7 @@ assign(JSContext      *cx,
 
 /* This preserves the previous behaviour of gjs_parse_args(), but maybe we want
  * to box primitive types instead of throwing? */
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext              *cx,
        char                    c,
@@ -91,7 +85,7 @@ assign(JSContext              *cx,
     ref.set(&value.toObject());
 }
 
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -118,7 +112,8 @@ assign(JSContext      *cx,
 
     *ref = tmp_ref.copy();
 }
-GNUC_ALWAYS_INLINE
+
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -134,7 +129,7 @@ assign(JSContext      *cx,
         throw g_strdup("Couldn't convert to integer");
 }
 
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -155,7 +150,7 @@ assign(JSContext      *cx,
     *ref = num;
 }
 
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -171,7 +166,7 @@ assign(JSContext      *cx,
         throw g_strdup("Couldn't convert to 64-bit integer");
 }
 
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -191,7 +186,7 @@ assign(JSContext      *cx,
  * prevent instantiation for any other types besides pointer-to-enum */
 template<typename T,
          typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 assign(JSContext      *cx,
        char            c,
@@ -217,7 +212,7 @@ template<typename T,
 static inline void
 free_if_necessary(T param_ref) {}
 
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 free_if_necessary(JS::MutableHandleObject param_ref)
 {
@@ -227,7 +222,7 @@ free_if_necessary(JS::MutableHandleObject param_ref)
     param_ref.set(NULL);
 }
 
-GNUC_ALWAYS_INLINE
+GJS_ALWAYS_INLINE
 static inline void
 free_if_necessary(char **param_ref)
 {
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 1b07601..e30c742 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -32,6 +32,12 @@
 #include "jsapi-wrapper.h"
 #include "gi/gtype.h"
 
+#ifdef __GNUC__
+#define GJS_ALWAYS_INLINE __attribute__((always_inline))
+#else
+#define GJS_ALWAYS_INLINE
+#endif
+
 class GjsAutoChar : public std::unique_ptr<char, decltype(&g_free)> {
 public:
     GjsAutoChar(char *str = nullptr) : unique_ptr(str, g_free) {}


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