Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data.table.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ SEXP fitsInInt64R(SEXP x);
bool allNA(SEXP x, bool errorForBadType);
SEXP colnamesInt(SEXP x, SEXP cols, SEXP check_dups, SEXP skip_absent);
bool INHERITS(SEXP x, SEXP char_);
void copyVectorElements(SEXP dst, SEXP src, R_xlen_t n, bool deep_copy, const char *caller);
SEXP copyAsPlain(SEXP x);
void copySharedColumns(SEXP x);
SEXP lock(SEXP x);
Expand Down
20 changes: 1 addition & 19 deletions src/dogroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,25 +526,7 @@ SEXP growVector(SEXP x, const R_len_t newlen)
UNPROTECT(1);
return newx;
}
switch (TYPEOF(x)) {
case RAWSXP: memcpy(RAW(newx), RAW_RO(x), len*RTYPE_SIZEOF(x)); break;
case LGLSXP: memcpy(LOGICAL(newx), LOGICAL_RO(x), len*RTYPE_SIZEOF(x)); break;
case INTSXP: memcpy(INTEGER(newx), INTEGER_RO(x), len*RTYPE_SIZEOF(x)); break;
case REALSXP: memcpy(REAL(newx), REAL_RO(x), len*RTYPE_SIZEOF(x)); break;
case CPLXSXP: memcpy(COMPLEX(newx), COMPLEX_RO(x), len*RTYPE_SIZEOF(x)); break;
case STRSXP : {
const SEXP *xd = SEXPPTR_RO(x);
for (int i=0; i<len; ++i)
SET_STRING_ELT(newx, i, xd[i]);
} break;
case VECSXP : {
const SEXP *xd = SEXPPTR_RO(x);
for (int i=0; i<len; ++i)
SET_VECTOR_ELT(newx, i, xd[i]);
} break;
default : // # nocov
internal_error(__func__, "type '%s' not supported", type2char(TYPEOF(x))); // # nocov
}
copyVectorElements(newx, x, (R_xlen_t)len, false, __func__);
// if (verbose) Rprintf(_("Growing vector from %d to %d items of type '%s'\n"), len, newlen, type2char(TYPEOF(x)));
// Would print for every column if here. Now just up in dogroups (one msg for each table grow).
SHALLOW_DUPLICATE_ATTRIB(newx, x);
Expand Down
64 changes: 37 additions & 27 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,42 @@ inline bool INHERITS(SEXP x, SEXP char_) {
return false;
}

void copyVectorElements(SEXP dst, SEXP src, R_xlen_t n, bool deep_copy, const char *caller) {
switch (TYPEOF(src)) {
case RAWSXP:
memcpy(RAW(dst), RAW_RO(src), n*sizeof(Rbyte));
break;
case LGLSXP:
memcpy(LOGICAL(dst), LOGICAL_RO(src), n*sizeof(int));
break;
case INTSXP:
memcpy(INTEGER(dst), INTEGER_RO(src), n*sizeof(int));
break;
case REALSXP:
memcpy(REAL(dst), REAL_RO(src), n*sizeof(double));
break;
case CPLXSXP:
memcpy(COMPLEX(dst), COMPLEX_RO(src), n*sizeof(Rcomplex));
break;
case STRSXP: {
const SEXP *xp = STRING_PTR_RO(src);
for (R_xlen_t i=0; i<n; ++i) SET_STRING_ELT(dst, i, xp[i]);
} break;
case VECSXP: {
const SEXP *xp = SEXPPTR_RO(src);
if (deep_copy) {
for (R_xlen_t i=0; i<n; ++i)
SET_VECTOR_ELT(dst, i, copyAsPlain(xp[i]));
} else {
for (R_xlen_t i=0; i<n; ++i)
SET_VECTOR_ELT(dst, i, xp[i]);
}
} break;
default: // # nocov
internal_error(__func__, "type '%s' not supported in %s", type2char(TYPEOF(src)), caller); // # nocov
}
}

SEXP copyAsPlain(SEXP x) {
// v1.12.2 and before used standard R duplicate() to do this. But duplicate() is not guaranteed to not return an ALTREP.
// e.g. ALTREP 'wrapper' on factor column (with materialized INTSXP) in package VIM under example(hotdeck)
Expand Down Expand Up @@ -240,33 +276,7 @@ SEXP copyAsPlain(SEXP x) {
UNPROTECT(1);
return ans;
}
switch (TYPEOF(x)) {
case RAWSXP:
memcpy(RAW(ans), RAW_RO(x), n*sizeof(Rbyte));
break;
case LGLSXP:
memcpy(LOGICAL(ans), LOGICAL_RO(x), n*sizeof(int));
break;
case INTSXP:
memcpy(INTEGER(ans), INTEGER_RO(x), n*sizeof(int)); // covered by 10:1 after test 178
break;
case REALSXP:
memcpy(REAL(ans), REAL_RO(x), n*sizeof(double)); // covered by as.Date("2013-01-01")+seq(1,1000,by=10) after test 1075
break;
case CPLXSXP:
memcpy(COMPLEX(ans), COMPLEX_RO(x), n*sizeof(Rcomplex));
break;
case STRSXP: {
const SEXP *xp=STRING_PTR_RO(x); // covered by as.character(as.hexmode(1:500)) after test 642
for (int64_t i=0; i<n; ++i) SET_STRING_ELT(ans, i, xp[i]);
} break;
case VECSXP: {
const SEXP *xp=SEXPPTR_RO(x);
for (int64_t i=0; i<n; ++i) SET_VECTOR_ELT(ans, i, copyAsPlain(xp[i]));
} break;
default: // # nocov
internal_error(__func__, "type '%s' not supported in %s", type2char(TYPEOF(x)), "copyAsPlain()"); // # nocov
}
copyVectorElements(ans, x, n, true, __func__);
DUPLICATE_ATTRIB(ans, x);
UNPROTECT(1);
return ans;
Expand Down
Loading