Wrap expensive SvTRUE macro in a function

The SvTRUE macro expands to a huge expression. Replacing it with a
function call in the XS wrappers reduces the code size of the Lucy
binary by about 30 KB on 32-bit.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/4aab73c2
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/4aab73c2
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/4aab73c2

Branch: refs/heads/master
Commit: 4aab73c25752f5cd6e68539418e85c914618a2de
Parents: 69dd42d
Author: Nick Wellnhofer <wellnho...@aevum.de>
Authored: Thu Nov 26 16:20:40 2015 +0100
Committer: Nick Wellnhofer <wellnho...@aevum.de>
Committed: Thu Nov 26 19:18:22 2015 +0100

----------------------------------------------------------------------
 compiler/src/CFCPerlTypeMap.c | 4 ++--
 runtime/perl/xs/XSBind.c      | 5 +++++
 runtime/perl/xs/XSBind.h      | 7 +++++++
 3 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4aab73c2/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c
index f320a82..2ac4985 100644
--- a/compiler/src/CFCPerlTypeMap.c
+++ b/compiler/src/CFCPerlTypeMap.c
@@ -108,7 +108,7 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var,
             result = CFCUtil_sprintf("(int8_t)SvIV(%s)", xs_var);
         }
         else if (strcmp(specifier, "bool") == 0) {
-            result = CFCUtil_sprintf("SvTRUE(%s) ? 1 : 0", xs_var);
+            result = CFCUtil_sprintf("XSBind_sv_true(aTHX_ %s)", xs_var);
         }
         else {
             FREEMEM(result);
@@ -212,7 +212,7 @@ static const char typemap_input[] =
     "INPUT\n"
     "\n"
     "CFISH_BOOL\n"
-    "    $var = ($type)SvTRUE($arg);\n"
+    "    $var = ($type)XSBind_sv_true(aTHX_ $arg);\n"
     "\n"
     "CFISH_SIGNED_INT \n"
     "    $var = ($type)SvIV($arg);\n"

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4aab73c2/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index 7b9e1e5..a03f5f7 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -88,6 +88,11 @@ XSBind_foster_obj(pTHX_ SV *sv, cfish_Class *klass) {
     return obj;
 }
 
+bool
+XSBind_sv_true(pTHX_ SV *sv) {
+    return !!SvTRUE(sv);
+}
+
 cfish_Obj*
 XSBind_perl_to_cfish(pTHX_ SV *sv, cfish_Class *klass) {
     cfish_Obj *retval = NULL;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4aab73c2/runtime/perl/xs/XSBind.h
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h
index a104797..40c98c7 100644
--- a/runtime/perl/xs/XSBind.h
+++ b/runtime/perl/xs/XSBind.h
@@ -71,6 +71,12 @@ cfish_XSBind_sv_defined(pTHX_ SV *sv) {
     return !!SvOK(sv);
 }
 
+/** Test whether an SV is true.  Wraps the expensive SvTRUE macro in a
+ * function.
+ */
+CFISH_VISIBLE bool
+cfish_XSBind_sv_true(pTHX_ SV *sv);
+
 /** Derive an SV from a Clownfish object.  If the Clownfish object is NULL, 
the SV
  * will be undef.  Doesn't invoke To_Host and always returns a reference to a
  * Clownfish::Obj.
@@ -208,6 +214,7 @@ cfish_XSBind_arg_to_cfish(pTHX_ SV *value, const char 
*label, bool nullable,
 #define XSBind_new_blank_obj           cfish_XSBind_new_blank_obj
 #define XSBind_foster_obj              cfish_XSBind_foster_obj
 #define XSBind_sv_defined              cfish_XSBind_sv_defined
+#define XSBind_sv_true                 cfish_XSBind_sv_true
 #define XSBind_cfish_obj_to_sv         cfish_XSBind_cfish_obj_to_sv
 #define XSBind_cfish_obj_to_sv_noinc   cfish_XSBind_cfish_obj_to_sv_noinc
 #define XSBind_cfish_to_perl           cfish_XSBind_cfish_to_perl

Reply via email to