Skip to content

Commit ee8590e

Browse files
committed
make chin branch more explicit
1 parent e5fd0f7 commit ee8590e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/chmatch.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatch
7171
for (int i = 0; i < tablelen; ++i) {
7272
int tl = hash_lookup(marks, td[i], 0);
7373
if (tl == -1) {
74-
hash_set(marks, td[i], chin ? 1 : i + 1);
74+
hash_set(marks, td[i], i + 1);
7575
nuniq--;
7676
if (nuniq == 0) break; // all found, stop scanning
7777
}
7878
}
7979

80-
const int not_found = chin ? 0 : nomatch;
81-
#pragma omp parallel for num_threads(getDTthreads(xlen, true))
82-
for (int i = 0; i < xlen; ++i) {
83-
int tl = hash_lookup(marks, xd[i], 0);
84-
ansd[i] = tl == -1 ? not_found : tl;
80+
if (chin) {
81+
#pragma omp parallel for num_threads(getDTthreads(xlen, true))
82+
for (int i = 0; i < xlen; ++i) {
83+
ansd[i] = hash_lookup(marks, xd[i], 0) > 0;
84+
}
85+
} else {
86+
#pragma omp parallel for num_threads(getDTthreads(xlen, true))
87+
for (int i = 0; i < xlen; ++i) {
88+
const int m = hash_lookup(marks, xd[i], 0);
89+
ansd[i] = (m < 0) ? nomatch : m;
90+
}
8591
}
8692
UNPROTECT(nprotect);
8793
return ans;

0 commit comments

Comments
 (0)