From 2041631d4ab9946b3f28efb84083508e1440f241 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Sat, 17 Jan 2026 19:50:03 +0100 Subject: [PATCH 1/3] extract helper --- src/data.table.h | 1 + src/dogroups.c | 20 +-------------- src/utils.c | 64 ++++++++++++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/data.table.h b/src/data.table.h index d6c67c752..9d9f6a6f1 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -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, int64_t n, bool deep_copy, const char *caller); SEXP copyAsPlain(SEXP x); void copySharedColumns(SEXP x); SEXP lock(SEXP x); diff --git a/src/dogroups.c b/src/dogroups.c index 7fd1b956e..343679645 100644 --- a/src/dogroups.c +++ b/src/dogroups.c @@ -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 Date: Sun, 18 Jan 2026 00:01:52 +0100 Subject: [PATCH 2/3] use __func__ instead of fixed strings --- src/dogroups.c | 2 +- src/utils.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dogroups.c b/src/dogroups.c index 343679645..b6b004c42 100644 --- a/src/dogroups.c +++ b/src/dogroups.c @@ -526,7 +526,7 @@ SEXP growVector(SEXP x, const R_len_t newlen) UNPROTECT(1); return newx; } - copyVectorElements(newx, x, (int64_t)len, false, "growVector()"); + copyVectorElements(newx, x, (int64_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); diff --git a/src/utils.c b/src/utils.c index 7e48e0a88..1a873f101 100644 --- a/src/utils.c +++ b/src/utils.c @@ -276,7 +276,7 @@ SEXP copyAsPlain(SEXP x) { UNPROTECT(1); return ans; } - copyVectorElements(ans, x, n, true, "copyAsPlain()"); + copyVectorElements(ans, x, n, true, __func__); DUPLICATE_ATTRIB(ans, x); UNPROTECT(1); return ans; From ea3a3fd0d95e25932b59d6a0b2cdca6857091713 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Mon, 19 Jan 2026 00:27:17 +0100 Subject: [PATCH 3/3] use R_xlen_t instead of int64_t --- src/data.table.h | 2 +- src/dogroups.c | 2 +- src/utils.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/data.table.h b/src/data.table.h index 9d9f6a6f1..e7ccc55d3 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -329,7 +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, int64_t n, bool deep_copy, const char *caller); +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); diff --git a/src/dogroups.c b/src/dogroups.c index b6b004c42..1085ceb5e 100644 --- a/src/dogroups.c +++ b/src/dogroups.c @@ -526,7 +526,7 @@ SEXP growVector(SEXP x, const R_len_t newlen) UNPROTECT(1); return newx; } - copyVectorElements(newx, x, (int64_t)len, false, __func__); + 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); diff --git a/src/utils.c b/src/utils.c index 1a873f101..106276fb6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -212,7 +212,7 @@ inline bool INHERITS(SEXP x, SEXP char_) { return false; } -void copyVectorElements(SEXP dst, SEXP src, int64_t n, bool deep_copy, const char *caller) { +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)); @@ -231,15 +231,15 @@ void copyVectorElements(SEXP dst, SEXP src, int64_t n, bool deep_copy, const cha break; case STRSXP: { const SEXP *xp = STRING_PTR_RO(src); - for (int64_t i=0; i