Skip to content

Commit 81898a1

Browse files
committed
various constness and read only-ness improvements
1 parent 59692e7 commit 81898a1

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/inrange.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
SEXP inrange(SEXP ansArg, SEXP xoArg, SEXP startsArg, SEXP lenArg)
55
{
66
int *ans = INTEGER(ansArg);
7-
const int *xo = INTEGER(xoArg);
8-
const int *starts = INTEGER(startsArg), *len = INTEGER(lenArg);
7+
const int *xo = INTEGER_RO(xoArg);
8+
const int *starts = INTEGER_RO(startsArg), *len = INTEGER_RO(lenArg);
99
const int n = length(startsArg), nxo = length(xoArg);
1010
for (int i = 0; i < n; i++) {
1111
for (int j = starts[i] - 1; j < starts[i] - 1 + len[i]; j++) {

src/programming.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ static void substitute_call_arg_names(SEXP expr, SEXP env)
77
SEXP arg_names = getAttrib(expr, R_NamesSymbol);
88
if (!isNull(arg_names)) {
99
SEXP env_names = getAttrib(env, R_NamesSymbol);
10-
int *imatches = INTEGER(PROTECT(chmatch(arg_names, env_names, 0)));
10+
const int *imatches = INTEGER_RO(PROTECT(chmatch(arg_names, env_names, 0)));
1111
const SEXP *env_sub = SEXPPTR_RO(env);
1212
SEXP tmp = expr;
1313
for (int i = 0; i < length(arg_names); i++, tmp = CDR(tmp)) { // substitute call arg names

src/reorder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SEXP reorder(SEXP x, SEXP order)
4242
int nprotect = 0;
4343
if (ALTREP(order)) { order=PROTECT(copyAsPlain(order)); nprotect++; } // TODO: if it's an ALTREP sequence some optimizations are possible rather than expand
4444

45-
const int *restrict idx = INTEGER(order);
45+
const int *restrict idx = INTEGER_RO(order);
4646
int i=0;
4747
while (i<nrow && idx[i] == i+1) ++i;
4848
const int start=i;

src/transpose.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ SEXP transpose(SEXP l, SEXP fill, SEXP ignoreArg, SEXP keepNamesArg, SEXP listCo
6161
} else PROTECT(li); // extra PROTECT just to help rchk by avoiding two counter variables
6262
switch (maxtype) {
6363
case LGLSXP: {
64-
const int *ili = LOGICAL(li);
65-
const int ifill = LOGICAL(fill)[0];
64+
const int *ili = LOGICAL_RO(li);
65+
const int ifill = LOGICAL_RO(fill)[0];
6666
for (int j = 0; j < maxlen; j++) {
6767
LOGICAL(ansp[j + rn])[k] = j < len ? ili[j] : ifill;
6868
}
6969
} break;
7070
case INTSXP: {
71-
const int *ili = INTEGER(li);
72-
const int ifill = INTEGER(fill)[0];
71+
const int *ili = INTEGER_RO(li);
72+
const int ifill = INTEGER_RO(fill)[0];
7373
for (int j = 0; j < maxlen; j++) {
7474
INTEGER(ansp[j + rn])[k] = j < len ? ili[j] : ifill;
7575
}
7676
} break;
7777
case REALSXP: {
78-
const double *dli = REAL(li);
79-
const double dfill = REAL(fill)[0];
78+
const double *dli = REAL_RO(li);
79+
const double dfill = REAL_RO(fill)[0];
8080
for (int j = 0; j < maxlen; j++) {
8181
REAL(ansp[j + rn])[k] = j < len ? dli[j] : dfill;
8282
}

src/types.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ SEXP testMsgR(SEXP status, SEXP x, SEXP k) {
7373
internal_error(__func__, "status, nx, nk must be integer"); // # nocov
7474
int protecti = 0;
7575
const bool verbose = GetVerbose();
76-
int istatus = INTEGER(status)[0], nx = INTEGER(x)[0], nk = INTEGER(k)[0];
76+
int istatus = INTEGER_RO(status)[0], nx = INTEGER_RO(x)[0], nk = INTEGER_RO(k)[0];
7777

7878
// TODO below chunk into allocAnsList helper - not easy for variable length of inner vectors
7979
SEXP ans = PROTECT(allocVector(VECSXP, nk * nx)); protecti++;

0 commit comments

Comments
 (0)