[Rcpp-commits] r1727 - pkg/Rcpp/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jun 25 12:34:25 CEST 2010


Author: romain
Date: 2010-06-25 12:34:25 +0200 (Fri, 25 Jun 2010)
New Revision: 1727

Modified:
   pkg/Rcpp/src/RcppFrame.cpp
Log:
wrap( RcppFrame ) factored out of RcppResultSet

Modified: pkg/Rcpp/src/RcppFrame.cpp
===================================================================
--- pkg/Rcpp/src/RcppFrame.cpp	2010-06-25 10:29:58 UTC (rev 1726)
+++ pkg/Rcpp/src/RcppFrame.cpp	2010-06-25 10:34:25 UTC (rev 1727)
@@ -296,27 +296,32 @@
 			
 			switch( table[0][i].getType() ){
 			case COLTYPE_DOUBLE :
+				{
 				value = PROTECT(Rf_allocVector(REALSXP,nrow));
 			    numProtected++;
-			    for (int j=0; j < nrow; j++)
-				REAL(value)[j] = table[j][i].getDoubleValue();
+			    double* p = REAL(value);
+			    for (int j=0; j < nrow; j++,p++)
+				p[j] = table[j][i].getDoubleValue();
 				break ;
-				
+				}
 			case COLTYPE_INT:
+				{
 				value = PROTECT(Rf_allocVector(INTSXP,nrow));
 			    numProtected++;
-			    for (int j=0; j < nrow; j++)
+			    int* p = INTEGER(value) ;
+			    for (int j=0; j < nrow; j++,p++)
 				INTEGER(value)[j] = table[j][i].getIntValue();
 				break ;
-				
+				}
 			case COLTYPE_FACTOR:
+				{
 				value = PROTECT(Rf_allocVector(INTSXP,nrow));
 			    numProtected++;
 			    levels = table[0][i].getFactorNumLevels();
-			    for (int k=0; k < levels; k++)
-				for (int j=0; j < nrow; j++) {
+			    int* p = INTEGER(value) ;
+			    for (int j=0; j < nrow; j++,p++) {
 				int level = table[j][i].getFactorLevel();
-				INTEGER(value)[j] = level;
+				p[j] = level;
 			    }
 			    Rf_setAttrib(value, R_LevelsSymbol, 
 			    	internal::factor_levels( 
@@ -324,7 +329,7 @@
 			    	);
 			    Rf_setAttrib(value, R_ClassSymbol, Rf_mkString("factor") );
 			    break ;
-			    
+			    }
 			case COLTYPE_STRING:
 			    value = PROTECT(Rf_allocVector(STRSXP,nrow));
 			    numProtected++;
@@ -336,26 +341,29 @@
 			case COLTYPE_LOGICAL:
 				value = PROTECT(Rf_allocVector(LGLSXP,nrow));
 			    numProtected++;
+			    int* p = LOGICAL(value) ;
 			    for (int j=0; j < nrow; j++) {
-				LOGICAL(value)[j] = table[j][i].getLogicalValue();
+				p[j] = table[j][i].getLogicalValue();
 			    }
 			    break;
 			    
 			case COLTYPE_DATE:    
 			    value = PROTECT(Rf_allocVector(REALSXP,nrow));
 			    numProtected++;
+			    double* p = REAL(value) ;
 			    for (int j=0; j < nrow; j++)
-				REAL(value)[j] = table[j][i].getDateRCode();
+				p[j] = table[j][i].getDateRCode();
 			    Rf_setAttrib(value, R_ClassSymbol, Rf_mkString("Date"));
 			    break; 
 			    
 			case COLTYPE_DATETIME:
 			    value = PROTECT(Rf_allocVector(REALSXP,nrow));
 			    numProtected++;
+			    double* p = REAL(value) ;
 			    for (int j=0; j < nrow; j++) {
 				// we could access the seconds as the internal double via getDouble but it's
 				// more proper to use the proper accessor (and if we ever added code ...)
-				REAL(value)[j] = table[j][i].getDatetimeValue().getFractionalTimestamp();
+				p[j] = table[j][i].getDatetimeValue().getFractionalTimestamp();
 			    }
 			    Rf_setAttrib(value, R_ClassSymbol, Rcpp::internal::getPosixClasses() );
 			    break; 



More information about the Rcpp-commits mailing list