From 2546daadedd14546b50fd8e5d464d1e3bb85cd6a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 2 Nov 2004 14:04:21 +0000 Subject: [PATCH] add branch predictions to re_string functions 2004-10-27 Paolo Bonzini * posix/regex_internal.c (re_string_reconstruct, re_string_context_at): Add several branch predictions for case-sensitive matching and no transition table being used. diff -ru lib_mio/regex_internal.c lib/regex_internal.c --- lib_mio/regex_internal.c 2004-10-27 12:47:44.000000000 +0200 +++ lib/regex_internal.c 2004-10-27 12:51:22.000000000 +0200 @@ -577,7 +577,7 @@ int idx, eflags; { int offset = idx - pstr->raw_mbs_idx; - if (offset < 0) + if (BE (offset < 0, 0)) { /* Reset buffer. */ #ifdef RE_ENABLE_I18N @@ -597,10 +597,10 @@ offset = idx; } - if (offset != 0) + if (BE (offset != 0, 1)) { /* Are the characters which are already checked remain? */ - if (offset < pstr->valid_raw_len + if (BE (offset < pstr->valid_raw_len, 1) #ifdef RE_ENABLE_I18N /* Handling this would enlarge the code too much. Accept a slowdown in that case. */ @@ -615,7 +615,7 @@ memmove (pstr->wcs, pstr->wcs + offset, (pstr->valid_len - offset) * sizeof (wint_t)); #endif /* RE_ENABLE_I18N */ - if (pstr->mbs_allocated) + if (BE (pstr->mbs_allocated, 0)) memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset); pstr->valid_len -= offset; @@ -713,7 +713,7 @@ ? CONTEXT_NEWLINE : 0)); } } - if (!pstr->mbs_allocated) + if (!BE (pstr->mbs_allocated, 0)) pstr->mbs += offset; } pstr->raw_mbs_idx = idx; @@ -735,16 +735,17 @@ } else #endif /* RE_ENABLE_I18N */ + if (BE (pstr->mbs_allocated, 0)) { if (pstr->icase) build_upper_buffer (pstr); else if (pstr->trans != NULL) re_string_translate_buffer (pstr); - else - pstr->valid_len = pstr->len; } - pstr->cur_idx = 0; + else + pstr->valid_len = pstr->len; + pstr->cur_idx = 0; return REG_NOERROR; } @@ -842,16 +843,13 @@ int idx, eflags; { int c; - if (idx < 0 || idx == input->len) - { - if (idx < 0) - /* In this case, we use the value stored in input->tip_context, - since we can't know the character in input->mbs[-1] here. */ - return input->tip_context; - else /* (idx == input->len) */ - return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF - : CONTEXT_NEWLINE | CONTEXT_ENDBUF); - } + if (BE (idx < 0, 0)) + /* In this case, we use the value stored in input->tip_context, + since we can't know the character in input->mbs[-1] here. */ + return input->tip_context; + if (BE (idx == input->len, 0)) + return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF + : CONTEXT_NEWLINE | CONTEXT_ENDBUF); #ifdef RE_ENABLE_I18N if (input->mb_cur_max > 1) { git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-3 --- lib/regex_internal.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/regex_internal.c b/lib/regex_internal.c index 96f1137..0f0aba0 100644 --- a/lib/regex_internal.c +++ b/lib/regex_internal.c @@ -581,7 +581,7 @@ re_string_reconstruct (pstr, idx, eflags) int idx, eflags; { int offset = idx - pstr->raw_mbs_idx; - if (offset < 0) + if (BE (offset < 0, 0)) { /* Reset buffer. */ #ifdef RE_ENABLE_I18N @@ -601,10 +601,10 @@ re_string_reconstruct (pstr, idx, eflags) offset = idx; } - if (offset != 0) + if (BE (offset != 0, 1)) { /* Are the characters which are already checked remain? */ - if (offset < pstr->valid_raw_len + if (BE (offset < pstr->valid_raw_len, 1) #ifdef RE_ENABLE_I18N /* Handling this would enlarge the code too much. Accept a slowdown in that case. */ @@ -619,7 +619,7 @@ re_string_reconstruct (pstr, idx, eflags) memmove (pstr->wcs, pstr->wcs + offset, (pstr->valid_len - offset) * sizeof (wint_t)); #endif /* RE_ENABLE_I18N */ - if (pstr->mbs_allocated) + if (BE (pstr->mbs_allocated, 0)) memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset); pstr->valid_len -= offset; @@ -717,7 +717,7 @@ re_string_reconstruct (pstr, idx, eflags) ? CONTEXT_NEWLINE : 0)); } } - if (!pstr->mbs_allocated) + if (!BE (pstr->mbs_allocated, 0)) pstr->mbs += offset; } pstr->raw_mbs_idx = idx; @@ -739,16 +739,17 @@ re_string_reconstruct (pstr, idx, eflags) } else #endif /* RE_ENABLE_I18N */ + if (BE (pstr->mbs_allocated, 0)) { if (pstr->icase) build_upper_buffer (pstr); else if (pstr->trans != NULL) re_string_translate_buffer (pstr); - else - pstr->valid_len = pstr->len; } - pstr->cur_idx = 0; + else + pstr->valid_len = pstr->len; + pstr->cur_idx = 0; return REG_NOERROR; } @@ -846,16 +847,13 @@ re_string_context_at (input, idx, eflags) int idx, eflags; { int c; - if (idx < 0 || idx == input->len) - { - if (idx < 0) - /* In this case, we use the value stored in input->tip_context, - since we can't know the character in input->mbs[-1] here. */ - return input->tip_context; - else /* (idx == input->len) */ - return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF - : CONTEXT_NEWLINE | CONTEXT_ENDBUF); - } + if (BE (idx < 0, 0)) + /* In this case, we use the value stored in input->tip_context, + since we can't know the character in input->mbs[-1] here. */ + return input->tip_context; + if (BE (idx == input->len, 0)) + return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF + : CONTEXT_NEWLINE | CONTEXT_ENDBUF); #ifdef RE_ENABLE_I18N if (input->mb_cur_max > 1) {