Skip to content

Commit de44468

Browse files
committed
Use LOGICAL_RO() instead of LOGICAL() in copyVector() to avoid ALTREP materialization
1 parent 09f3acb commit de44468

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/main/duplicate.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,23 +382,23 @@ void copyVector(SEXP s, SEXP t)
382382
xcopyStringWithRecycle(s, t, 0, ns, nt);
383383
break;
384384
case LGLSXP:
385-
xcopyLogicalWithRecycle(LOGICAL(s), LOGICAL(t), 0, ns, nt);
385+
xcopyLogicalWithRecycle(LOGICAL(s), LOGICAL_RO(t), 0, ns, nt);
386386
break;
387387
case INTSXP:
388-
xcopyIntegerWithRecycle(INTEGER(s), INTEGER(t), 0, ns, nt);
388+
xcopyIntegerWithRecycle(INTEGER(s), INTEGER_RO(t), 0, ns, nt);
389389
break;
390390
case REALSXP:
391-
xcopyRealWithRecycle(REAL(s), REAL(t), 0, ns, nt);
391+
xcopyRealWithRecycle(REAL(s), REAL_RO(t), 0, ns, nt);
392392
break;
393393
case CPLXSXP:
394-
xcopyComplexWithRecycle(COMPLEX(s), COMPLEX(t), 0, ns, nt);
394+
xcopyComplexWithRecycle(COMPLEX(s), COMPLEX_RO(t), 0, ns, nt);
395395
break;
396396
case EXPRSXP:
397397
case VECSXP:
398398
xcopyVectorWithRecycle(s, t, 0, ns, nt);
399399
break;
400400
case RAWSXP:
401-
xcopyRawWithRecycle(RAW(s), RAW(t), 0, ns, nt);
401+
xcopyRawWithRecycle(RAW(s), RAW_RO(t), 0, ns, nt);
402402
break;
403403
default:
404404
UNIMPLEMENTED_TYPE("copyVector", s);
@@ -486,7 +486,7 @@ void copyMatrix(SEXP s, SEXP t, Rboolean byrow)
486486

487487
#define COPY_WITH_RECYCLE(VALTYPE, TNAME) \
488488
attribute_hidden void \
489-
xcopy##TNAME##WithRecycle(VALTYPE *dst, VALTYPE *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc) { \
489+
xcopy##TNAME##WithRecycle(VALTYPE *dst, const VALTYPE *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc) { \
490490
\
491491
if (nsrc >= n) { /* no recycle needed */ \
492492
for(R_xlen_t i = 0; i < n; i++) \

src/main/duplicate.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ Iterator macro to fill a matrix from a vector with re-use of vector
4242
(sidx >= nsrc) ? sidx -= nsrc : 0, \
4343
didx += drows)
4444

45-
void xcopyComplexWithRecycle(Rcomplex *dst, Rcomplex *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
46-
void xcopyIntegerWithRecycle(int *dst, int *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
47-
void xcopyLogicalWithRecycle(int *dst, int *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
48-
void xcopyRawWithRecycle(Rbyte *dst, Rbyte *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
49-
void xcopyRealWithRecycle(double *dst, double *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
45+
void xcopyComplexWithRecycle(Rcomplex *dst, const Rcomplex *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
46+
void xcopyIntegerWithRecycle(int *dst, const int *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
47+
void xcopyLogicalWithRecycle(int *dst, const int *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
48+
void xcopyRawWithRecycle(Rbyte *dst, const Rbyte *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
49+
void xcopyRealWithRecycle(double *dst, const double *src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
5050
void xcopyStringWithRecycle(SEXP dst, SEXP src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
5151
void xcopyVectorWithRecycle(SEXP dst, SEXP src, R_xlen_t dstart, R_xlen_t n, R_xlen_t nsrc);
5252

0 commit comments

Comments
 (0)