|
1 | 1 | #include "data.table.h" |
| 2 | +#include <string.h> |
2 | 3 |
|
3 | 4 | // TODO: Add oxygen style comments and cleanup var names. |
4 | 5 | // See other TODOs inside the function. |
5 | 6 | SEXP nqRecreateIndices(SEXP xo, SEXP len, SEXP indices, SEXP nArg, SEXP nomatch) |
6 | 7 | { |
7 | | - R_len_t n = INTEGER(nArg)[0], xn = length(xo); |
| 8 | + const R_len_t n = INTEGER_RO(nArg)[0], xn = length(xo); |
8 | 9 | SEXP ans, newstarts, newlen; |
9 | 10 | ans = PROTECT(allocVector(VECSXP, 2)); |
10 | 11 | SET_VECTOR_ELT(ans, 0, (newstarts = allocVector(INTSXP, n))); |
11 | 12 | SET_VECTOR_ELT(ans, 1, (newlen = allocVector(INTSXP, n))); |
12 | 13 |
|
13 | 14 | int *inewlen = INTEGER(newlen); |
14 | | - const int *iindices = INTEGER(indices); |
15 | | - const int *ilen = INTEGER(len); |
16 | | - const int *ixo = INTEGER(xo); |
17 | | - const int inomatch = isNull(nomatch) ? 0 : INTEGER(nomatch)[0]; |
| 15 | + const int *iindices = INTEGER_RO(indices); |
| 16 | + const int *ilen = INTEGER_RO(len); |
| 17 | + const int *ixo = INTEGER_RO(xo); |
| 18 | + const int inomatch = isNull(nomatch) ? 0 : INTEGER_RO(nomatch)[0]; |
18 | 19 | int *inewstarts = INTEGER(newstarts); |
19 | 20 |
|
20 | | - for (int i = 0; i < n; i++) inewlen[i] = 0; |
| 21 | + memset(inewlen, 0, n * sizeof(int)); |
21 | 22 |
|
22 | 23 | // simplifying logic ... also fixes #2275 |
23 | 24 | for (int i = 0; i < length(indices); i++) { |
|
0 commit comments