From 537ad7e6dae1d7f370a6d876a753260c578574c5 Mon Sep 17 00:00:00 2001 From: Sebastian Krantz Date: Sun, 23 Jun 2024 14:49:46 +0200 Subject: [PATCH] Replace STRING_PTR. --- src/TRA.c | 38 +++++++++++++++++++------------------- src/base_radixsort.c | 2 +- src/base_radixsort.h | 2 ++ src/data.table.h | 5 ++--- src/data.table_rbindlist.c | 16 ++++++++-------- src/data.table_subset.c | 10 +++++----- src/data.table_utils.c | 10 +++++----- src/ffirst.c | 12 ++++++------ src/flast.c | 14 +++++++------- src/fmode.c | 18 +++++++++--------- src/fndistinct.c | 12 ++++++------ src/fnobs.c | 8 ++++---- src/gsplit.c | 16 ++++++++-------- src/join.c | 4 ++-- src/kit.h | 4 +++- src/kit_dup.c | 16 ++++++++-------- src/match.c | 22 +++++++++++----------- src/pivot.c | 6 +++--- src/programming.c | 24 ++++++++++++------------ src/small_helper.c | 8 ++++---- 20 files changed, 125 insertions(+), 122 deletions(-) diff --git a/src/TRA.c b/src/TRA.c index 154c8ca6..92b3bf09 100644 --- a/src/TRA.c +++ b/src/TRA.c @@ -125,13 +125,13 @@ SEXP ret1(SEXP x, SEXP xAG, SEXP g, int set) { } case STRSXP: { - SEXP *pout = STRING_PTR(out); + SEXP *pout = SEXPPTR(out); if(nog) { SEXP AG = asChar(xAG); #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = AG; } else { - SEXP *AG = STRING_PTR(xAG)-1; + SEXP *AG = SEXPPTR(xAG)-1; #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = AG[pg[i]]; } @@ -237,13 +237,13 @@ SEXP ret2(SEXP x, SEXP xAG, SEXP g, int set) { break; } case STRSXP: { - SEXP *pout = STRING_PTR(out); + SEXP *pout = SEXPPTR(out); if(nog) { SEXP AG = asChar(xAG); #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = ISNAN(px[i]) ? NA_STRING : AG; } else { - SEXP *AG = STRING_PTR(xAG)-1; + SEXP *AG = SEXPPTR(xAG)-1; #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = ISNAN(px[i]) ? NA_STRING : AG[pg[i]]; } @@ -287,13 +287,13 @@ SEXP ret2(SEXP x, SEXP xAG, SEXP g, int set) { break; } case STRSXP: { - SEXP *pout = STRING_PTR(out); + SEXP *pout = SEXPPTR(out); if(nog) { SEXP AG = asChar(xAG); #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = (px[i] == NA_INTEGER) ? NA_STRING : AG; } else { - SEXP *AG = STRING_PTR(xAG)-1; + SEXP *AG = SEXPPTR(xAG)-1; #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = (px[i] == NA_INTEGER) ? NA_STRING : AG[pg[i]]; } @@ -306,7 +306,7 @@ SEXP ret2(SEXP x, SEXP xAG, SEXP g, int set) { } case STRSXP: { - SEXP *px = STRING_PTR(x); + SEXP *px = SEXPPTR(x); switch(txAG) { case REALSXP: { double *pout = REAL(out); @@ -336,13 +336,13 @@ SEXP ret2(SEXP x, SEXP xAG, SEXP g, int set) { break; } case STRSXP: { - SEXP *pout = STRING_PTR(out); + SEXP *pout = SEXPPTR(out); if(nog) { SEXP AG = asChar(xAG); #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = (px[i] == NA_STRING) ? NA_STRING : AG; } else { - SEXP *AG = STRING_PTR(xAG)-1; + SEXP *AG = SEXPPTR(xAG)-1; #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = (px[i] == NA_STRING) ? NA_STRING : AG[pg[i]]; } @@ -448,7 +448,7 @@ SEXP ret0(SEXP x, SEXP xAG, SEXP g, int set) { } case STRSXP: { - SEXP *px = STRING_PTR(x), *pout = STRING_PTR(out); + SEXP *px = SEXPPTR(x), *pout = SEXPPTR(out); if(nog) { SEXP AG = asChar(xAG); #pragma omp simd @@ -459,7 +459,7 @@ SEXP ret0(SEXP x, SEXP xAG, SEXP g, int set) { case LGLSXP: case INTSXP: error("Cannot replace missing values in string with numeric data"); case STRSXP: { - SEXP *AG = STRING_PTR(xAG)-1; + SEXP *AG = SEXPPTR(xAG)-1; #pragma omp simd for(int i = 0; i < l; ++i) pout[i] = (px[i] == NA_STRING) ? AG[pg[i]] : px[i]; break; @@ -728,7 +728,7 @@ SEXP TRAlC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { break; } case STRSXP: { - SEXP *pAG = STRING_PTR(xAG); + SEXP *pAG = SEXPPTR(xAG); RETLOOPS(ScalarString(pAG[j])) break; } @@ -814,7 +814,7 @@ SEXP TRAmC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { } case STRSXP: { - SEXP *pout = STRING_PTR(out), *pAG = STRING_PTR(xAG); + SEXP *pout = SEXPPTR(out), *pAG = SEXPPTR(xAG); if(nog) { for(int j = 0; j != col; ++j) { int s = j * row, e = s + row; @@ -883,7 +883,7 @@ SEXP TRAmC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { } case STRSXP: { - SEXP *pout = STRING_PTR(out), *pAG = STRING_PTR(xAG); + SEXP *pout = SEXPPTR(out), *pAG = SEXPPTR(xAG); if(nog) { for(int j = 0; j != col; ++j) { int s = j * row, e = s + row; @@ -951,7 +951,7 @@ SEXP TRAmC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { } case STRSXP: { - SEXP *pout = STRING_PTR(out), *pAG = STRING_PTR(xAG); + SEXP *pout = SEXPPTR(out), *pAG = SEXPPTR(xAG); if(nog) { for(int j = 0; j != col; ++j) { int s = j * row, e = s + row; @@ -975,7 +975,7 @@ SEXP TRAmC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { } case STRSXP: { - SEXP *px = STRING_PTR(x); + SEXP *px = SEXPPTR(x); switch(txAG) { case REALSXP: { @@ -1018,7 +1018,7 @@ SEXP TRAmC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { } case STRSXP: { - SEXP *pout = STRING_PTR(out), *pAG = STRING_PTR(xAG); + SEXP *pout = SEXPPTR(out), *pAG = SEXPPTR(xAG); if(nog) { for(int j = 0; j != col; ++j) { int s = j * row, e = s + row; @@ -1165,14 +1165,14 @@ SEXP TRAmC(SEXP x, SEXP xAG, SEXP g, SEXP Rret, SEXP Rset) { } case STRSXP: { - SEXP *px = STRING_PTR(x), *pout = STRING_PTR(out); + SEXP *px = SEXPPTR(x), *pout = SEXPPTR(out); switch(txAG) { case REALSXP: case INTSXP: case LGLSXP: error("Cannot replace missing values in string with numeric data"); case STRSXP: { - SEXP *pAG = STRING_PTR(xAG); + SEXP *pAG = SEXPPTR(xAG); if(nog) { for(int j = 0; j != col; ++j) { int s = j * row, e = s + row; diff --git a/src/base_radixsort.c b/src/base_radixsort.c index 3ef55f1c..c217d153 100644 --- a/src/base_radixsort.c +++ b/src/base_radixsort.c @@ -931,7 +931,7 @@ static int StrCmp(SEXP x, SEXP y) // also used by bmerge and chmatch void checkEncodings(SEXP x) // static { cetype_t ce; - SEXP *px = STRING_PTR(x); + SEXP *px = SEXPPTR(x); int i, lx = length(x); for (i = 0; i != lx && px[i] == NA_STRING; ++i); diff --git a/src/base_radixsort.h b/src/base_radixsort.h index aa4858b8..2d5283f3 100644 --- a/src/base_radixsort.h +++ b/src/base_radixsort.h @@ -8,6 +8,8 @@ // #define IS_ASCII(x) ((x)->sxpinfo.gp & ASCII_MASK) // #define IS_ASCII(x) (LEVELS(x) & ASCII_MASK) +#define SEXPPTR(x) ((SEXP *)DATAPTR(x)) // Replacing STRING_PTR + // NOTE: All of this is copied from Defn.h: https://github.com/wch/r-source/blob/28de75af0541f93832c5899139b969d290bf422e/src/include/Defn.h // to avoid checking for ALTREP in TRUELENGTH, which slows down the code unnecessarily... diff --git a/src/data.table.h b/src/data.table.h index 42be1773..3a1e348a 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -3,10 +3,9 @@ and licensed under a Mozilla Public License 2.0 (MPL-2.0) license. */ -#include #define USE_RINTERNALS -#include -#include // for uint64_t rather than unsigned long long +#include "base_radixsort.h" +// #include // for uint64_t rather than unsigned long long #include // #include "types.h" diff --git a/src/data.table_rbindlist.c b/src/data.table_rbindlist.c index 05018ea1..09e3829b 100644 --- a/src/data.table_rbindlist.c +++ b/src/data.table_rbindlist.c @@ -38,7 +38,7 @@ void writeNA(SEXP v, const int from, const int n) for (int i=from; i<=to; ++i) vd[i] = NA_CPLX; } break; case STRSXP: { - SEXP *vd = STRING_PTR(v); + SEXP *vd = SEXPPTR(v); for (int i=from; i<=to; ++i) vd[i] = NA_STRING; } break; case VECSXP: @@ -262,7 +262,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg) if (isNull(li) || !LENGTH(li)) continue; const SEXP cn = getAttrib(li, R_NamesSymbol); if (!length(cn)) continue; - const SEXP *cnp = STRING_PTR(cn); + const SEXP *cnp = SEXPPTR(cn); for (int j=0; j a a regular factor because this case isn't yet implemented. a // #include -#include // needed for intptr_t on linux +#include // needed for uintptr_t on linux // #include // #ifdef _OPENMP // #include @@ -45,6 +45,7 @@ // #define SEXP_T ScalarLogical(TRUE) #define NOGE(x, l) ((x < 0) || (x >= l)) #define HASH(key, K) (3141592653U * (unsigned int)(key) >> (32 - (K))) +#define HASHK(key, K) (3141592653U * (unsigned int)(key) >> (K)) #define N_ISNAN(x, y) (!ISNAN(x) && !ISNAN(y)) #define B_IsNA(x, y) (R_IsNA(x) && R_IsNA(y)) #define B_IsNaN(x, y) (R_IsNaN(x) && R_IsNaN(y)) @@ -54,6 +55,7 @@ #define C_ISNAN(x, y) (B_ISNAN(x, y) || (N_ISNAN(x, y) && x == y)) #define REQUAL(x, y) (N_ISNAN(x, y) ? (x == y) : (B_IsNA(x, y) || B_IsNaN(x, y))) #define CEQUAL(x, y) ((N_ISNAN(x.r, x.i) && N_ISNAN(y.r, y.i)) ? (x.r == y.r && x.i == y.i) : (C_IsNA(x) ? C_IsNA(y) : (C_IsNA(y) ? 0 : (C_ISNAN(x.r, y.r) && C_ISNAN(x.i, y.i))))) +#define SEXPPTR(x) ((SEXP *)DATAPTR(x)) // To replace STRING_PTR // #define STR_DF mkString("data.frame") // #define MAX(a,b) (((a)>(b))?(a):(b)) // #define IS_LOGICAL(x) (isLogical(x) && LENGTH(x)==1) diff --git a/src/kit_dup.c b/src/kit_dup.c index 07a99953..22f6452a 100644 --- a/src/kit_dup.c +++ b/src/kit_dup.c @@ -175,7 +175,7 @@ SEXP dupVecIndex(SEXP x) { } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(x); + const SEXP *restrict px = SEXPPTR(x); for (int i = 0; i != n; ++i) { id = HASH(((uintptr_t) px[i] & 0xffffffff), K); while(h[id]) { @@ -338,7 +338,7 @@ SEXP dupVecIndexKeepNA(SEXP x) { } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(x); + const SEXP *restrict px = SEXPPTR(x); for (int i = 0; i != n; ++i) { if(px[i] == NA_STRING) { pans_i[i] = NA_INTEGER; @@ -452,7 +452,7 @@ SEXP dupVecIndexTwoVectors(SEXP x, SEXP y) { } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR_RO(x), *restrict py = STRING_PTR_RO(y); + const SEXP *restrict px = SEXPPTR_RO(x), *restrict py = SEXPPTR_RO(y); for (int i = 0; i != n; ++i) { id = HASH(64988430769U * ((uintptr_t)px[i] & 0xffffffff) + ((uintptr_t)py[i] & 0xffffffff), K); // Best combination it seems while(h[id]) { @@ -513,7 +513,7 @@ SEXP dupVecIndexTwoVectors(SEXP x, SEXP y) { } // Second case: real and string } else if ((tx == REALSXP && ty == STRSXP) || (tx == STRSXP && ty == REALSXP)) { - const SEXP *restrict ps = STRING_PTR_RO(tx == STRSXP ? x : y); + const SEXP *restrict ps = SEXPPTR_RO(tx == STRSXP ? x : y); const double *restrict pr = REAL_RO(tx == REALSXP ? x : y); union uno tpv; for (int i = 0; i != n; ++i) { @@ -534,7 +534,7 @@ SEXP dupVecIndexTwoVectors(SEXP x, SEXP y) { // Third case: integer and string } else if((tx == INTSXP && ty == STRSXP) || (tx == STRSXP && ty == INTSXP)) { const int *restrict pi = INTEGER_RO(tx == INTSXP ? x : y); - const SEXP *restrict ps = STRING_PTR_RO(tx == STRSXP ? x : y); + const SEXP *restrict ps = SEXPPTR_RO(tx == STRSXP ? x : y); for (int i = 0; i != n; ++i) { id = HASH(pi[i] * ((uintptr_t)ps[i] & 0xffffffff), K); while(h[id]) { @@ -702,7 +702,7 @@ int dupVecSecond(int *restrict pidx, int *restrict pans_i, SEXP x, const int n, } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(x); + const SEXP *restrict px = SEXPPTR(x); const unsigned int mult = (M-1) / ng; // -1 because C is zero indexed for (int i = 0; i != n; ++i) { id = (pidx[i]*mult) ^ HASH(((uintptr_t) px[i] & 0xffffffff), K); // HASH(((uintptr_t) px[i] & 0xffffffff) ^ pidx[i], K) + pidx[i]; @@ -984,7 +984,7 @@ SEXP funiqueC(SEXP x) { for(int i = 0; i != g; ++i) pres[i] = px[st[i]]; } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(x); + const SEXP *restrict px = SEXPPTR(x); for (int i = 0; i != n; ++i) { id = HASH(((uintptr_t) px[i] & 0xffffffff), K); while(h[id]) { @@ -1001,7 +1001,7 @@ SEXP funiqueC(SEXP x) { return x; } PROTECT(res = allocVector(STRSXP, g)); ++nprotect; - SEXP *restrict pres = STRING_PTR(res); + SEXP *restrict pres = SEXPPTR(res); for(int i = 0; i != g; ++i) pres[i] = px[st[i]]; } break; } diff --git a/src/match.c b/src/match.c index 2fc97489..c0d8f5e8 100644 --- a/src/match.c +++ b/src/match.c @@ -250,7 +250,7 @@ SEXP match_single(SEXP x, SEXP table, SEXP nomatch) { } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(x), *restrict pt = STRING_PTR(table); + const SEXP *restrict px = SEXPPTR(x), *restrict pt = SEXPPTR(table); // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { id = HASH(((uintptr_t) pt[i] & 0xffffffff), K); @@ -428,8 +428,8 @@ SEXP match_two_vectors(SEXP x, SEXP table, SEXP nomatch) { } } break; case STRSXP: { - const SEXP *restrict px1 = STRING_PTR(pc1[0]), *restrict px2 = STRING_PTR(pc2[0]), - *restrict pt1 = STRING_PTR(pc1[1]), *restrict pt2 = STRING_PTR(pc2[1]); + const SEXP *restrict px1 = SEXPPTR(pc1[0]), *restrict px2 = SEXPPTR(pc2[0]), + *restrict pt1 = SEXPPTR(pc1[1]), *restrict pt2 = SEXPPTR(pc2[1]); // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { id = HASH(64988430769U * ((uintptr_t)pt1[i] & 0xffffffff) + ((uintptr_t)pt2[i] & 0xffffffff), K); @@ -523,7 +523,7 @@ SEXP match_two_vectors(SEXP x, SEXP table, SEXP nomatch) { } else if ((t1 == REALSXP && t2 == STRSXP) || (t1 == STRSXP && t2 == REALSXP)) { const int rev = t1 == STRSXP; const double *restrict pxr = REAL(VECTOR_ELT(pc[rev], 0)), *restrict ptr = REAL(VECTOR_ELT(pc[rev], 1)); - const SEXP *restrict pxs = STRING_PTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = STRING_PTR(VECTOR_ELT(pc[1-rev], 1)); + const SEXP *restrict pxs = SEXPPTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = SEXPPTR(VECTOR_ELT(pc[1-rev], 1)); union uno tpv; // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { @@ -554,7 +554,7 @@ SEXP match_two_vectors(SEXP x, SEXP table, SEXP nomatch) { } else if((t1 == INTSXP && t2 == STRSXP) || (t1 == STRSXP && t2 == INTSXP)) { const int rev = t1 == STRSXP; const int *restrict pxi = INTEGER(VECTOR_ELT(pc[rev], 0)), *restrict pti = INTEGER(VECTOR_ELT(pc[rev], 1)); - const SEXP *restrict pxs = STRING_PTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = STRING_PTR(VECTOR_ELT(pc[1-rev], 1)); + const SEXP *restrict pxs = SEXPPTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = SEXPPTR(VECTOR_ELT(pc[1-rev], 1)); // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { @@ -643,8 +643,8 @@ void match_two_vectors_extend(const SEXP *pc, const int nmv, const int n, const } } break; case STRSXP: { - const SEXP *restrict px1 = STRING_PTR(pc1[0]), *restrict px2 = STRING_PTR(pc2[0]), - *restrict pt1 = STRING_PTR(pc1[1]), *restrict pt2 = STRING_PTR(pc2[1]); + const SEXP *restrict px1 = SEXPPTR(pc1[0]), *restrict px2 = SEXPPTR(pc2[0]), + *restrict pt1 = SEXPPTR(pc1[1]), *restrict pt2 = SEXPPTR(pc2[1]); // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { id = HASH(64988430769U * ((uintptr_t)pt1[i] & 0xffffffff) + ((uintptr_t)pt2[i] & 0xffffffff), K); @@ -747,7 +747,7 @@ void match_two_vectors_extend(const SEXP *pc, const int nmv, const int n, const } else if ((t1 == REALSXP && t2 == STRSXP) || (t1 == STRSXP && t2 == REALSXP)) { const int rev = t1 == STRSXP; const double *restrict pxr = REAL(VECTOR_ELT(pc[rev], 0)), *restrict ptr = REAL(VECTOR_ELT(pc[rev], 1)); - const SEXP *restrict pxs = STRING_PTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = STRING_PTR(VECTOR_ELT(pc[1-rev], 1)); + const SEXP *restrict pxs = SEXPPTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = SEXPPTR(VECTOR_ELT(pc[1-rev], 1)); union uno tpv; // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { @@ -781,7 +781,7 @@ void match_two_vectors_extend(const SEXP *pc, const int nmv, const int n, const } else if((t1 == INTSXP && t2 == STRSXP) || (t1 == STRSXP && t2 == INTSXP)) { const int rev = t1 == STRSXP; const int *restrict pxi = INTEGER(VECTOR_ELT(pc[rev], 0)), *restrict pti = INTEGER(VECTOR_ELT(pc[rev], 1)); - const SEXP *restrict pxs = STRING_PTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = STRING_PTR(VECTOR_ELT(pc[1-rev], 1)); + const SEXP *restrict pxs = SEXPPTR(VECTOR_ELT(pc[1-rev], 0)), *restrict pts = SEXPPTR(VECTOR_ELT(pc[1-rev], 1)); // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { @@ -871,7 +871,7 @@ void match_additional(const SEXP *pcj, const int nmv, const int n, const int nt, } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(pcj[0]), *restrict pt = STRING_PTR(pcj[1]); + const SEXP *restrict px = SEXPPTR(pcj[0]), *restrict pt = SEXPPTR(pcj[1]); // fill hash table with indices of 'table' for (int i = 0; i != nt; ++i) { if(ptab_copy[i] == nmv) { @@ -964,7 +964,7 @@ void match_rest(const SEXP *pcj, const int nmv, const int n, const int nt, int * } } break; case STRSXP: { - const SEXP *restrict px = STRING_PTR(pcj[0]), *restrict pt = STRING_PTR(pcj[1])-1; + const SEXP *restrict px = SEXPPTR(pcj[0]), *restrict pt = SEXPPTR(pcj[1])-1; for (int i = 0; i != n; ++i) { if(pans[i] == nmv) continue; if(px[i] != pt[pans[i]]) pans[i] = nmv; diff --git a/src/pivot.c b/src/pivot.c index 4934000f..a3a61c8a 100644 --- a/src/pivot.c +++ b/src/pivot.c @@ -119,7 +119,7 @@ SEXP pivot_long(SEXP data, SEXP ind, SEXP idcol) { pid += end; ++v; } } else { - SEXP *restrict pid = STRING_PTR(id_column), *pnam = STRING_PTR(names); + SEXP *restrict pid = SEXPPTR(id_column), *pnam = SEXPPTR(names); for (int j = 0, end = 0; j != l; ++j) { SEXP namj = pnam[j]; end = length(pind[j]); // SIMD?? @@ -314,9 +314,9 @@ SEXP pivot_wide(SEXP index, SEXP id, SEXP column, SEXP fill, SEXP Rnthreads, SEX break; } case STRSXP: { - const SEXP *restrict pc = STRING_PTR_RO(column); + const SEXP *restrict pc = SEXPPTR_RO(column); if(aggfun > 3) error("Cannot aggregate character column with sum, mean, min, or max."); - AGGFUN_SWITCH_CAT(STRING_PTR, pc[i] != NA_STRING); + AGGFUN_SWITCH_CAT(SEXPPTR, pc[i] != NA_STRING); break; } case VECSXP: diff --git a/src/programming.c b/src/programming.c index aca30e4f..8b88229f 100644 --- a/src/programming.c +++ b/src/programming.c @@ -31,11 +31,11 @@ SEXP Cna_rm(SEXP x) { return out; } case STRSXP: { - const SEXP *xd = STRING_PTR(x); + const SEXP *xd = SEXPPTR(x); for (int i = 0; i != n; ++i) if(xd[i] == NA_STRING) ++k; if(k == 0) return x; SEXP out = PROTECT(allocVector(STRSXP, n - k)); - SEXP *pout = STRING_PTR(out); + SEXP *pout = SEXPPTR(out); k = 0; for (int i = 0; i != n; ++i) if(xd[i] != NA_STRING) pout[k++] = xd[i]; copyMostAttrib(x, out); @@ -60,7 +60,7 @@ SEXP Cna_rm(SEXP x) { // Helper function to find a single string in factor levels int fchmatch(SEXP x, SEXP val, int nomatch) { - const SEXP *px = STRING_PTR(x), v = asChar(val); + const SEXP *px = SEXPPTR(x), v = asChar(val); for(int i = 0, l = length(x); i != l; ++i) if(px[i] == v) return i + 1; return nomatch; } @@ -109,8 +109,8 @@ if(length(val) == n && n > 1) { } case STRSXP: { - const SEXP *px = STRING_PTR(x); - const SEXP *pv = STRING_PTR(val); + const SEXP *px = SEXPPTR(x); + const SEXP *pv = SEXPPTR(val); WHICHVLOOPLX break; } @@ -155,7 +155,7 @@ if(length(val) == n && n > 1) { } case STRSXP: { - const SEXP *px = STRING_PTR(x); + const SEXP *px = SEXPPTR(x); const SEXP v = PROTECT(asChar(val)); WHICHVLOOP UNPROTECT(1); @@ -216,7 +216,7 @@ case REALSXP: } case STRSXP: { - const SEXP *px = STRING_PTR(x); + const SEXP *px = SEXPPTR(x); const SEXP v = asChar(val); ALLANYVLOOP break; @@ -387,7 +387,7 @@ SEXP setcopyv(SEXP x, SEXP val, SEXP rep, SEXP Rinvert, SEXP Rset, SEXP Rind1) { } case STRSXP: { - SEXP *restrict px = set ? STRING_PTR(x) : STRING_PTR(ans); + SEXP *restrict px = set ? SEXPPTR(x) : SEXPPTR(ans); if(lv == 1 && ind1 == 0) { const SEXP v = PROTECT(asChar(val)); if(lr == 1) { @@ -395,7 +395,7 @@ SEXP setcopyv(SEXP x, SEXP val, SEXP rep, SEXP Rinvert, SEXP Rset, SEXP Rind1) { setcopyvLOOP(r) UNPROTECT(1); } else { - const SEXP *restrict pr = STRING_PTR(rep); + const SEXP *restrict pr = SEXPPTR(rep); setcopyvLOOP(pr[i]) } UNPROTECT(1); @@ -406,7 +406,7 @@ SEXP setcopyv(SEXP x, SEXP val, SEXP rep, SEXP Rinvert, SEXP Rset, SEXP Rind1) { setcopyvLOOPLVEC1 UNPROTECT(1); } else { - const SEXP *restrict pr = STRING_PTR(rep); + const SEXP *restrict pr = SEXPPTR(rep); setcopyvLOOPLVEC } } @@ -760,7 +760,7 @@ SEXP na_locf(SEXP x, SEXP Rset) { } case STRSXP: { - SEXP *data = STRING_PTR(x); + SEXP *data = SEXPPTR(x); SEXP last = data[0]; for (int i = 0; i < n; i++) { if (data[i] == NA_STRING) { @@ -826,7 +826,7 @@ SEXP na_focb(SEXP x, SEXP Rset) { } case STRSXP: { - SEXP *data = STRING_PTR(x); + SEXP *data = SEXPPTR(x); SEXP last = data[0]; for (int i = n; i--; ) { if (data[i] == NA_STRING) { diff --git a/src/small_helper.c b/src/small_helper.c index 8c4e8731..8b8d1d22 100644 --- a/src/small_helper.c +++ b/src/small_helper.c @@ -66,7 +66,7 @@ SEXP falloc(SEXP value, SEXP n, SEXP simplify) { break; } case STRSXP: { - SEXP val = asChar(value), *pout = STRING_PTR(out); + SEXP val = asChar(value), *pout = SEXPPTR(out); for(int i = 0; i != l; ++i) pout[i] = val; break; } @@ -169,7 +169,7 @@ SEXP multiassign(SEXP lhs, SEXP rhs, SEXP envir) { return R_NilValue; } if(length(rhs) != n) error("length(lhs) must be equal to length(rhs)"); - SEXP *plhs = STRING_PTR(lhs); + SEXP *plhs = SEXPPTR(lhs); switch(TYPEOF(rhs)) { // installTrChar translates to native encoding, installChar does the same now, but also is available on older systems. case REALSXP: { double *prhs = REAL(rhs); @@ -188,7 +188,7 @@ SEXP multiassign(SEXP lhs, SEXP rhs, SEXP envir) { break; } case STRSXP: { - SEXP *prhs = STRING_PTR(rhs); + SEXP *prhs = SEXPPTR(rhs); for(int i = 0; i < n; ++i) { SEXP nam = installChar(plhs[i]); defineVar(nam, ScalarString(prhs[i]), envir); @@ -235,7 +235,7 @@ SEXP vlabels(SEXP x, SEXP attrn, SEXP usenam) { return labx; } SEXP res = PROTECT(allocVector(STRSXP, l)); - SEXP *pres = STRING_PTR(res); + SEXP *pres = SEXPPTR(res); const SEXP *px = SEXPPTR_RO(x); for(int i = 0; i < l; ++i) { SEXP labxi = getAttrib(px[i], sym_attrn);