[Rcpp-commits] r1867 - in pkg/Rcpp: . inst inst/include/Rcpp/vector src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 17 14:42:14 CEST 2010


Author: romain
Date: 2010-07-17 14:42:14 +0200 (Sat, 17 Jul 2010)
New Revision: 1867

Modified:
   pkg/Rcpp/NEWS
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
   pkg/Rcpp/src/RObject.cpp
Log:
faster RObject::slot using R API functions instead of R callbacks

Modified: pkg/Rcpp/NEWS
===================================================================
--- pkg/Rcpp/NEWS	2010-07-17 08:04:23 UTC (rev 1866)
+++ pkg/Rcpp/NEWS	2010-07-17 12:42:14 UTC (rev 1867)
@@ -1,7 +1,7 @@
 0.8.5   (future)
 
-	o	speed improvements. assigning vector names is faster as it avoids
-		making a callback to R if not necessary. 
+	o	speed improvements. Vector::names, RObject::slot have been improved
+		to take advantage of R API functions instead of callbacks to R
 
 0.8.4   2010-07-09
 

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-07-17 08:04:23 UTC (rev 1866)
+++ pkg/Rcpp/inst/ChangeLog	2010-07-17 12:42:14 UTC (rev 1867)
@@ -1,8 +1,11 @@
 2010-07-17  Romain Francois <romain at r-enthusiasts.com>
 
-	* inst/include/vector/Vector.h: faster lhs use of names, only using callback
+	* inst/include/Rcpp/vector/Vector.h: faster lhs use of names, only using callback
 	to R if necessary. (discovered while profiling RProtoBuf)
 	
+	* inst/include/Rcpp/RObject.h : faster lhs and rhs use of RObject::slot, 
+	using R API functions R_do_slot and R_do_slot_assign
+	
 2010-07-16  Romain Francois <romain at r-enthusiasts.com>
 
 	* man/Rcpp-package.Rd : removed old content and point to the Rcpp-package

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-07-17 08:04:23 UTC (rev 1866)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-07-17 12:42:14 UTC (rev 1867)
@@ -256,11 +256,7 @@
 				Rf_lcons( Rf_install("names<-"), 
 						Rf_cons( parent, Rf_cons( x , R_NilValue) )))) ;
 				/* names<- makes a new vector, so we have to change 
-				   the SEXP of the parent of this proxy, it might be 
-				   worth to work directly with the names attribute instead
-				   of using the names<- R function, but then we need to 
-				   take care of coercion, recycling, etc ... we cannot just 
-				   brutally assign the names attribute */
+				   the SEXP of the parent of this proxy */
 				const_cast<Vector&>(parent).setSEXP( new_vec ) ;
 				UNPROTECT(1) ; /* new_vec */
     			}

Modified: pkg/Rcpp/src/RObject.cpp
===================================================================
--- pkg/Rcpp/src/RObject.cpp	2010-07-17 08:04:23 UTC (rev 1866)
+++ pkg/Rcpp/src/RObject.cpp	2010-07-17 12:42:14 UTC (rev 1867)
@@ -101,19 +101,16 @@
 
 
 SEXP RObject::SlotProxy::get() const {
-	return internal::try_catch( 
-		Rf_lcons( Rf_install("slot"), Rf_cons( parent , 
-			Rf_cons( Rf_mkString(slot_name.c_str()) , R_NilValue)))) ; 
-			
+	return R_do_slot( parent, Rf_install( slot_name.c_str() ) ) ;	
 }
 
 void RObject::SlotProxy::set( SEXP x) const {
-	SEXP new_obj = PROTECT( 
-		internal::try_catch( 
-			Rf_lcons( Rf_install("slot<-"), 
-					Rf_cons( parent, Rf_cons( Rf_mkString(slot_name.c_str()), 
-						Rf_cons( Rf_ScalarLogical(TRUE) , 
-							Rf_cons( x , R_NilValue)  ) ))))) ;
+	// the SEXP might change (.Data)
+	SEXP new_obj = PROTECT( R_do_slot_assign( 
+		parent, 
+		Rf_install( slot_name.c_str() ), 
+		x
+		) ) ;
 	const_cast<RObject&>(parent).setSEXP( new_obj ) ;
 	UNPROTECT(1) ;
 }



More information about the Rcpp-commits mailing list