diff --git a/src/kwset.c b/src/kwset.c index d5db12f..9163482 100644 --- a/src/kwset.c +++ b/src/kwset.c @@ -494,29 +494,32 @@ bmexec (kwset_t kwset, char const *text, size_t size) /* Significance of 12: 1 (initial offset) + 10 (skip loop) + 1 (md2). */ if (size > 12 * len) /* 11 is not a bug, the initial offset happens only once. */ - for (ep = text + size - 11 * len;;) + for (ep = text + size - 11 * len; tp <= ep; ) { - while (tp <= ep) + d = d1[U(tp[-1])], tp += d; + d = d1[U(tp[-1])], tp += d; + if (d != 0) { d = d1[U(tp[-1])], tp += d; d = d1[U(tp[-1])], tp += d; - if (d == 0) - goto found; - d = d1[U(tp[-1])], tp += d; - d = d1[U(tp[-1])], tp += d; - d = d1[U(tp[-1])], tp += d; - if (d == 0) - goto found; - d = d1[U(tp[-1])], tp += d; - d = d1[U(tp[-1])], tp += d; - d = d1[U(tp[-1])], tp += d; - if (d == 0) - goto found; - d = d1[U(tp[-1])], tp += d; d = d1[U(tp[-1])], tp += d; + if (d != 0) + { + d = d1[U(tp[-1])], tp += d; + d = d1[U(tp[-1])], tp += d; + d = d1[U(tp[-1])], tp += d; + if (d != 0) + { + /* It's typically faster to use memchr when there is + no chance to match for a while. */ + tp = memchr (tp - 1, gc1, text + size - (tp - 1)); + if (! tp) + return -1; + tp++; + } + } } - break; - found: + d = len; while (true) {