[Dplr-commits] r677 - branches/redfit/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 3 15:01:10 CEST 2013


Author: mvkorpel
Date: 2013-09-03 15:01:10 +0200 (Tue, 03 Sep 2013)
New Revision: 677

Modified:
   branches/redfit/src/redfit.c
Log:
Use memcpy for copying


Modified: branches/redfit/src/redfit.c
===================================================================
--- branches/redfit/src/redfit.c	2013-09-03 11:45:50 UTC (rev 676)
+++ branches/redfit/src/redfit.c	2013-09-03 13:01:10 UTC (rev 677)
@@ -22,6 +22,7 @@
 #include <Rinternals.h>
 #include <Rmath.h>
 #include <complex.h>
+#include <string.h>
 
 SEXP seg50(SEXP k, SEXP nseg, SEXP segskip, SEXP np);
 void rmtrend(SEXP x, SEXP y, SEXP lengthfun, SEXP lmfit);
@@ -91,7 +92,7 @@
     SEXP tmp, lmcall, lmres, lmnames, rduals;
     SEXP sn, ncall;
     PROTECT_INDEX ipx;
-    double *rdualsptr, *y_data;
+    double *y_data;
     size_t i, nameslength;
     size_t n = 0;
     Rboolean found = FALSE;
@@ -144,11 +145,8 @@
 
     y_data = REAL(y);
     if (!mismatch) {
-	rdualsptr = REAL(rduals);
 	/* dplR: Copy residuals over y */
-	for (i = 0; i < n; i++) {
-	    y_data[i] = rdualsptr[i];
-	}
+	memcpy(y_data, REAL(rduals), n * sizeof(double));
     } else {
 	for (i = 0; i < n; i++) {
 	    y_data[i] = NA_REAL;
@@ -169,7 +167,7 @@
     SEXP gxx, twk, xwk, ftrx, ftix, tmp, cbindcall, lengthfun;
     double dnseg, segskip_val, scal, np_val;
     long double sumx, sqrt_nseg;
-    size_t i, j, nseg_val, nfreq_val, n50_val, segstart;
+    size_t i, j, nseg_val, nfreq_val, n50_val, segstart, ncopy;
     size_t sincos_skip, wtau_skip;
     size_t wwidx = 0;
     double *t_data, *x_data, *ww_data, *tsin_data, *tcos_data, *wtau_data;
@@ -227,13 +225,12 @@
 	gxx_data[i] = 0.0;
     }
     lengthfun = install("length");
+    ncopy = nseg_val * sizeof(double);
     for (i = 0; i < n50_val; i++) {
 	/* copy data of i'th segment into workspace */
 	segstart = (size_t) segfirst((double) i, segskip_val, np_val, dnseg);
-	for (j = 0; j < nseg_val; j++) {
-	    twk_data[j] = t_data[segstart + j];
-	    xwk_data[j] = x_data[segstart + j];
-	}
+	memcpy(twk_data, t_data + segstart, ncopy);
+	memcpy(xwk_data, x_data + segstart, ncopy);
 	/* detrend data */
 	rmtrend(twk, xwk, lengthfun, lmfit);
         /* apply window to data */



More information about the Dplr-commits mailing list