From 2041631d4ab9946b3f28efb84083508e1440f241 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger Date: Sat, 17 Jan 2026 19:50:03 +0100 Subject: [PATCH 1/6] 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/6] 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/6] 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 Date: Thu, 22 Jan 2026 07:34:30 +0100 Subject: [PATCH 4/6] remove ws Co-authored-by: Michael Chirico --- src/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index 106276fb6..b6d14c916 100644 --- a/src/utils.c +++ b/src/utils.c @@ -243,8 +243,8 @@ void copyVectorElements(SEXP dst, SEXP src, R_xlen_t n, bool deep_copy, const ch SET_VECTOR_ELT(dst, i, xp[i]); } } break; - default: // # nocov - internal_error(__func__, "type '%s' not supported in %s", type2char(TYPEOF(src)), caller); // # nocov + default: // # nocov + internal_error(__func__, "type '%s' not supported in %s", type2char(TYPEOF(src)), caller); // # nocov } } From fd7cbc42b12dd3b6b8a390c1e45aedf7e6105954 Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com> Date: Thu, 22 Jan 2026 07:34:55 +0100 Subject: [PATCH 5/6] add comment to signature Co-authored-by: Michael Chirico --- src/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index b6d14c916..5ccf75e7a 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, __func__); + copyVectorElements(ans, x, n, /*deep_copy=*/true, __func__); DUPLICATE_ATTRIB(ans, x); UNPROTECT(1); return ans; From 4afc587a54b75882c31b719119c226d9f56fa11d Mon Sep 17 00:00:00 2001 From: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com> Date: Thu, 22 Jan 2026 07:35:22 +0100 Subject: [PATCH 6/6] visual tightening Co-authored-by: Michael Chirico --- src/utils.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/utils.c b/src/utils.c index 5ccf75e7a..be8770dc6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -235,13 +235,8 @@ void copyVectorElements(SEXP dst, SEXP src, R_xlen_t n, bool deep_copy, const ch } break; case VECSXP: { const SEXP *xp = SEXPPTR_RO(src); - if (deep_copy) { - for (R_xlen_t i=0; i