[Rcpp-commits] r2897 - in pkg/Rcpp: . inst/include/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 13 17:33:11 CET 2011


Author: edd
Date: 2011-02-13 17:33:11 +0100 (Sun, 13 Feb 2011)
New Revision: 2897

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
Log:
added inline function to cache Rf_install("Module") for loading of a module


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-02-12 01:45:59 UTC (rev 2896)
+++ pkg/Rcpp/ChangeLog	2011-02-13 16:33:11 UTC (rev 2897)
@@ -1,3 +1,12 @@
+2011-02-13  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/include/Rcpp/Module.h: Cache return of Rf_install("Module") in
+	an inline helper function used by the LOAD_RCPP_MODULE macro
+
+2011-02-11  Dirk Eddelbuettel  <edd at debian.org>
+
+        * inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Added two more examples
+
 2011-02-10  Douglas Bates  <bates at stat.wisc.edu>
 
 	* inst/include/Rcpp/XPtr.h: Replace calls to EXTPTR_PTR with

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2011-02-12 01:45:59 UTC (rev 2896)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2011-02-13 16:33:11 UTC (rev 2897)
@@ -739,9 +739,16 @@
 }                                                                    \
 void _rcpp_module_##name##_init()
 
-#define LOAD_RCPP_MODULE(NAME) 							\
-    SEXP moduleSym = Rf_install("Module");					\
-    Rf_eval( Rf_lang2( moduleSym, _rcpp_module_boot_##NAME() ), R_GlobalEnv )
+// helper function to cache the result of Rf_install("Module"): once
+// it is allocated and in the symbol table it is safe from gc
+inline SEXP getModuleSym() {
+    static SEXP moduleSym = NULL;
+    if (moduleSym == NULL) {
+	moduleSym = Rf_install("Module");
+    }
+    return moduleSym;
+}
+#define LOAD_RCPP_MODULE(NAME) Rf_eval( Rf_lang2( getModuleSym(), _rcpp_module_boot_##NAME() ), R_GlobalEnv )
 
 
 #endif



More information about the Rcpp-commits mailing list