aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/search.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-06-07 22:02:56 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-06-07 22:02:56 +0200
commite0c5b2bd7d4abf971d1fa6039704a44af334e3e2 (patch)
tree3f4799d33299af2d4fa73aa1924440616ba5f47e /src/search.c
parentd03667b609c91a18fe975686b8519a2599138dc3 (diff)
fixup aa7b0bb1445feeefafdcf47fd639b10500b45c03: some minor optimizationsHEADmaster-fmsbw-cimaster
A partial match __should__ always be at the end of the subject string (i.e. block), so we don't have to check for it. Also, partial matches will be rare, so we can discriminate against the branch that handles them.
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/search.c b/src/search.c
index 92be012..90975c2 100644
--- a/src/search.c
+++ b/src/search.c
@@ -751,7 +751,12 @@ teco_do_search_backwards(GRegex *re, gsize from, gsize to, gint *count, GError *
return FALSE;
}
- if (g_match_info_is_partial_match(info)) {
+ if (g_match_info_matches(info)) {
+ g_free(matched->matches[i].ranges);
+ matched->matches[i].ranges = teco_get_ranges(info, from+from_block,
+ &matched->matches[i].num_ranges);
+ i = ++matched_total % matched_num;
+ } else if (G_UNLIKELY(g_match_info_is_partial_match(info))) {
/*
* Match may fall on the block boundary,
* so retry matching the rest of the document.
@@ -769,32 +774,27 @@ teco_do_search_backwards(GRegex *re, gsize from, gsize to, gint *count, GError *
rc = g_match_info_fetch_pos(info, 0, &partial_start, &partial_end);
//g_assert(rc == TRUE);
if (!rc)
+ /* make sure that test case fails */
abort();
+ g_assert(partial_end == to_block-from_block);
- if (partial_end == to_block-from_block) {
- g_autoptr(GMatchInfo) partial_info = NULL;
+ g_autoptr(GMatchInfo) partial_info = NULL;
- g_regex_match_full(re, buffer+partial_start, to-from-partial_start, 0,
- G_REGEX_MATCH_ANCHORED, &partial_info, &tmp_error);
- if (tmp_error) {
- g_propagate_error(error, tmp_error);
- return FALSE;
- }
-
- if (g_match_info_matches(partial_info)) {
- g_free(matched->matches[i].ranges);
- matched->matches[i].ranges = teco_get_ranges(partial_info, from+partial_start,
- &matched->matches[i].num_ranges);
- i = ++matched_total % matched_num;
- }
+ g_regex_match_full(re, buffer+partial_start, to-from-partial_start, 0,
+ G_REGEX_MATCH_ANCHORED, &partial_info, &tmp_error);
+ if (tmp_error) {
+ g_propagate_error(error, tmp_error);
+ return FALSE;
+ }
+
+ if (g_match_info_matches(partial_info)) {
+ g_free(matched->matches[i].ranges);
+ matched->matches[i].ranges = teco_get_ranges(partial_info, from+partial_start,
+ &matched->matches[i].num_ranges);
+ i = ++matched_total % matched_num;
}
/* there might still be other matches within the current block */
- } else if (g_match_info_matches(info)) {
- g_free(matched->matches[i].ranges);
- matched->matches[i].ranges = teco_get_ranges(info, from+from_block,
- &matched->matches[i].num_ranges);
- i = ++matched_total % matched_num;
} else {
break;
}