[Rcpp-commits] r2207 - pkg/Rcpp/inst/include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 27 12:22:27 CEST 2010


Author: romain
Date: 2010-09-27 12:22:26 +0200 (Mon, 27 Sep 2010)
New Revision: 2207

Modified:
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
some more loop unrolling

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-09-27 10:02:04 UTC (rev 2206)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2010-09-27 10:22:26 UTC (rev 2207)
@@ -95,27 +95,40 @@
 	}
     
 private:
-	
+	  
+    // TODO: do some dispatch when VEC == Vector so that we use std::copy
     template <bool NA, typename VEC>
-    inline void import_expression__iterator( const VectorBase<RTYPE,NA,VEC>& other, int n, Rcpp::traits::true_type ){
+    inline void import_expression( const VectorBase<RTYPE,NA,VEC>& other, int n ){
+        iterator start = begin() ; 
         const VEC& ref = other.get_ref() ;
-		std::copy( ref.begin(), ref.end(), begin() ) ;
-	}
-    
-    template <bool NA, typename VEC>
-    inline void import_expression__iterator( const VectorBase<RTYPE,NA,VEC>& other, int n, Rcpp::traits::false_type ){
-        iterator start = begin() ; 
-		const VEC& ref = other.get_ref() ;
-    	for( int i=0; i<n; i++, ++start){
-			*start = ref[i] ;
-		}
+        
+        int __trip_count = n >> 2 ;
+        int i = 0 ;
+    	for ( ; __trip_count > 0 ; --__trip_count) { 
+        	start[i] = ref[i] ; i++ ;            
+        	start[i] = ref[i] ; i++ ;            
+        	start[i] = ref[i] ; i++ ;            
+        	start[i] = ref[i] ; i++ ;            
+    	}                                            
+    	switch (n - i){                          
+    	  case 3:                                    
+    	      start[i] = ref[i] ; i++ ;             
+          case 2:                                    
+    	      start[i] = ref[i] ; i++ ;             
+    	  case 1:                                    
+    	      start[i] = ref[i] ; i++ ;             
+    	  case 0:                                    
+    	  default:                                   
+    	      {}                         
+    	}
     }
     
-    template <bool NA, typename VEC>
-    inline void import_expression( const VectorBase<RTYPE,NA,VEC>& other, int n ){
-    	import_expression__iterator<NA,VEC>( other, n, typename Rcpp::traits::has_iterator<VEC>::type( ) ) ;
-    }
-
+    // template <>
+    // inline void import_expression<true,Vector>( const VectorBase<RTYPE,NA,VEC>& other, int n ){
+    //     const VEC& ref = other.get_ref() ;
+    //     std::copy( ref.begin(), ref.end(), begin() ) ;
+	// }
+    
     template <typename T>
     inline void fill_or_generate( const T& t){
     	fill_or_generate__impl( t, typename traits::is_generator<T>::type() ) ;



More information about the Rcpp-commits mailing list