--- regexec-save.c Wed Oct 23 10:16:49 2002 +++ regexec.c Wed Oct 23 10:53:13 2002 @@ -173,7 +173,9 @@ static int group_nodes_into_DFAstates (c static int check_node_accept (const regex_t *preg, const re_token_t *node, const re_match_context_t *mctx, int idx); static reg_errcode_t extend_buffers (re_match_context_t *mctx); +static inline int my_memcmp (char *s1, char *s2, unsigned int l); + /* Entry point for POSIX code. */ /* regexec searches for a given pattern, specified by PREG, in the @@ -1049,8 +1051,8 @@ proceed_next_node (preg, nregs, regs, mc else if (naccepted) { char *buf = re_string_get_buffer (mctx->input); - if (strncmp (buf + regs[subexp_idx].rm_so, buf + *pidx, - naccepted) != 0) + if (my_memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx, + naccepted) != 0) return -1; } } @@ -1821,7 +1823,7 @@ search_subexp (preg, mctx, sctx, str_idx return err; } buf = (char *) re_string_get_buffer (mctx->input); - if (strncmp (buf + str_idx, buf + bkref_str_idx, subexp_len) != 0) + if (my_memcmp (buf + str_idx, buf + bkref_str_idx, subexp_len) != 0) break; if (sctx->limits.nelem && str_idx > 0) @@ -1983,8 +1985,8 @@ sift_states_bkref (preg, mctx, sctx, str { char *buf; buf = (char *) re_string_get_buffer (mctx->input); - if (strncmp (buf + entry->subexp_from, - buf + cur_bkref_idx, subexp_len) != 0) + if (my_memcmp (buf + entry->subexp_from, + buf + cur_bkref_idx, subexp_len) != 0) continue; err = match_ctx_add_entry (mctx, dfa, sctx->cur_bkref, cur_bkref_idx, entry->subexp_from, @@ -3230,3 +3232,14 @@ sift_ctx_init (sctx, sifted_sts, limited sctx->cls_subexp_idx = -1; re_node_set_init_empty (&sctx->limits); } + +/* This function is optimized to compare for equality only. + It also tries to limit the startup time as much as possible. */ +static int my_memcmp (char *s1, char *s2, unsigned int l) +{ + if (BE(l, 1) != 0) + while (BE(*s1 == *s2, 1) && BE(--l, 0) != 0) + s1++, s2++; + + return l; +}