[Rcpp-commits] r2776 - in pkg/Rcpp: inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 12 10:16:24 CET 2010


Author: romain
Date: 2010-12-12 10:16:24 +0100 (Sun, 12 Dec 2010)
New Revision: 2776

Modified:
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/src/Module.cpp
Log:
reuse the same string in many places

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2010-12-12 09:08:36 UTC (rev 2775)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2010-12-12 09:16:24 UTC (rev 2776)
@@ -57,8 +57,8 @@
 	    name(name_), docstring( doc == 0 ? "" : doc ){} ;
 	
 	virtual Rcpp::List fields(SEXP){ return Rcpp::List(0); }
-	virtual Rcpp::List getMethods(SEXP){ return Rcpp::List(0); }
-	virtual Rcpp::List getConstructors(SEXP){ return Rcpp::List(0); }
+	virtual Rcpp::List getMethods(SEXP, std::string&){ return Rcpp::List(0); }
+	virtual Rcpp::List getConstructors(SEXP, std::string&){ return Rcpp::List(0); }
 	
 	virtual void run_finalizer(SEXP){ }
 	
@@ -220,13 +220,12 @@
 template <typename Class>
 class S4_CppConstructor : public Rcpp::Reference {
 public:             
-    S4_CppConstructor( SignedConstructor<Class>* m, SEXP class_xp, const std::string& class_name ) : Reference( "C++Constructor" ){
+    S4_CppConstructor( SignedConstructor<Class>* m, SEXP class_xp, const std::string& class_name, std::string& buffer ) : Reference( "C++Constructor" ){
         field( "pointer" )       = Rcpp::XPtr< SignedConstructor<Class> >( m, false ) ;
         field( "class_pointer" ) = class_xp ;
         field( "nargs" )         = m->nargs() ;
-        std::string sign ;
-        m->signature( sign, class_name ) ;
-        field( "signature" )     = sign ;
+        m->signature( buffer, class_name ) ;
+        field( "signature" )     = buffer ;
         field( "docstring" )     = m->docstring ;
     }
 } ;
@@ -237,20 +236,19 @@
     typedef SignedMethod<Class> signed_method_class ;
 	typedef std::vector<signed_method_class*> vec_signed_method ;
 	
-	S4_CppOverloadedMethods( vec_signed_method* m, SEXP class_xp, const char* name ) : Reference( "C++OverloadedMethods" ){
+	S4_CppOverloadedMethods( vec_signed_method* m, SEXP class_xp, const char* name, std::string& buffer ) : Reference( "C++OverloadedMethods" ){
         
 	    int n = m->size() ;
         Rcpp::LogicalVector voidness(n), constness(n) ;
         Rcpp::CharacterVector docstrings(n), signatures(n) ;
         signed_method_class* met ;
-        std::string sign ;
         for( int i=0; i<n; i++){ 
             met = m->at(i) ;
             voidness[i] = met->is_void() ;
             constness[i] = met->is_const() ;
             docstrings[i] = met->docstring ;
-            met->signature(sign, name) ;
-            signatures[i] = sign ;
+            met->signature(buffer, name) ;
+            signatures[i] = buffer ;
         }
         
 	    field( "pointer" )       = Rcpp::XPtr< vec_signed_method >( m, false ) ;
@@ -651,7 +649,7 @@
 		return out ;
 	}
 
-	Rcpp::List getMethods( SEXP class_xp ){
+	Rcpp::List getMethods( SEXP class_xp, std::string& buffer){
 	    int n = vec_methods.size() ;
 		Rcpp::CharacterVector mnames(n) ;
 		Rcpp::List res(n) ;
@@ -660,18 +658,18 @@
 	    for( int i=0; i<n; i++, ++it){
 		    mnames[i] = it->first ;
 		    v = it->second ;
-		    res[i] = S4_CppOverloadedMethods<Class>( v , class_xp, it->first.c_str() ) ;
+		    res[i] = S4_CppOverloadedMethods<Class>( v , class_xp, it->first.c_str(), buffer ) ;
 		}
 		res.names() = mnames ;
 	    return res ;
 	}
 	
-	Rcpp::List getConstructors( SEXP class_xp){
+	Rcpp::List getConstructors( SEXP class_xp, std::string& buffer){
 	    int n = constructors.size() ;
 		Rcpp::List out(n) ;
 		typename vec_signed_constructor::iterator it = constructors.begin( ) ;
 		for( int i=0; i<n; i++, ++it){
-			out[i] = S4_CppConstructor<Class>( *it , class_xp, name ) ; 
+			out[i] = S4_CppConstructor<Class>( *it , class_xp, name, buffer ) ; 
 		} 
 		return out ;
 	}
@@ -716,7 +714,7 @@
 class CppClass : public S4{
 public:
 	typedef Rcpp::XPtr<Rcpp::Module> XP ;
-	CppClass( Module* p, class_Base* clazz ) ;
+	CppClass( Module* p, class_Base* clazz, std::string& ) ;
 	CppClass( SEXP x) ;
 } ;
 

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2010-12-12 09:08:36 UTC (rev 2775)
+++ pkg/Rcpp/src/Module.cpp	2010-12-12 09:16:24 UTC (rev 2776)
@@ -316,9 +316,10 @@
 		Rcpp::CharacterVector names(n) ;
 		Rcpp::List info(n);
 		CLASS_MAP::iterator it = classes.begin() ;
+		std::string buffer ;
 		for( int i=0; i<n; i++, ++it){
 			names[i] = it->first ;
-			info[i]  = CppClass( this , it->second ) ;
+			info[i]  = CppClass( this , it->second, buffer ) ;
 		}
 		info.names() = names ;
 		return info ;
@@ -383,19 +384,19 @@
 	
 	CppClass::CppClass( SEXP x) : S4(x){}
 	
-	CppClass::CppClass( Module* p, class_Base* cl ) : S4("C++Class") {
+	CppClass::CppClass( Module* p, class_Base* cl, std::string& buffer ) : S4("C++Class") {
 		XP_Class clxp( cl, false, R_NilValue, R_NilValue ) ;
 		
 		slot( "module"  ) = XP( p, false ) ;
 		slot( "pointer" ) = clxp ;
 		
-		std::string mangled_name( "Rcpp_" ) ;
-		mangled_name += cl->name ;
-		slot( ".Data" ) = mangled_name ;
+		buffer = "Rcpp_" ;
+		buffer += cl->name ;
+		slot( ".Data" ) = buffer ;
 		
 		slot( "fields" )      = cl->fields( clxp.asSexp() ) ;
-		slot( "methods" )     = cl->getMethods( clxp.asSexp() ) ;
-		slot( "constructors") = cl->getConstructors( clxp.asSexp() ) ;
+		slot( "methods" )     = cl->getMethods( clxp.asSexp(), buffer ) ;
+		slot( "constructors") = cl->getConstructors( clxp.asSexp(), buffer ) ;
 		slot( "docstring"   ) = cl->docstring ;
 	}
 
@@ -409,7 +410,8 @@
 		BEGIN_RCPP
 			CLASS_MAP::iterator it = classes.find(cl) ;
 			if( it == classes.end() ) throw std::range_error( "no such class" ) ;
-			return CppClass( this, it->second ) ;
+			std::string buffer ;
+			return CppClass( this, it->second, buffer ) ;
 		END_RCPP
 	}
 	



More information about the Rcpp-commits mailing list