Skip to content

Commit c490a4e

Browse files
committed
outlined the INTEGER function for performance (+ cleanup)
1 parent d875823 commit c490a4e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/fmelt.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ static const char *concat(SEXP vec, SEXP idx) {
103103
// with missing inputs, and -1 in the positions with column names not
104104
// found. Column names not found will eventually cause error via
105105
// uniq_diff().
106-
SEXP chmatch_na(SEXP x, SEXP table){
107-
SEXP ans;
108-
PROTECT(ans = chmatch(x, table, -1));
109-
for(int i=0; i<length(ans); i++){
110-
if(STRING_ELT(x, i) == NA_STRING){
111-
INTEGER(ans)[i] = NA_INTEGER;
106+
SEXP chmatch_na(SEXP x, SEXP table)
107+
{
108+
SEXP ans = chmatch(x, table, -1);
109+
PROTECT(ans);
110+
int *restrict target = INTEGER(ans);
111+
for (int i = 0; i < length(ans); i++) {
112+
if (STRING_ELT(x, i) == NA_STRING) {
113+
target[i] = NA_INTEGER;
112114
}
113115
}
114116
UNPROTECT(1);

0 commit comments

Comments
 (0)