ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit ad0d991dd8b10d443519ff87996c2df6ff68a14c
parent 2671263a0b51069f287e267fa4fefbaf5b83b8ae
Author: Jacob R. Edwards <n/a>
Date:   Sun, 11 Dec 2022 19:45:02 -0600

Improve find functions

"Rewinding" the starting position for negative numeric searches was
done in findnext() instead of renewsearch() for whatever reason.
There is no functional difference in doing this in renewsearch(),
but it keeps findnext() focused on it's task, increases efficiency
by removing an unnessisary test, and gets rid of a search struct
member.

It's simply a more correct way of doing things.

Diffstat:
Maps/find.c | 21+++++++++------------
Maps/find.h | 1-
2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/aps/find.c b/aps/find.c @@ -66,7 +66,15 @@ renewsearch(struct search *state, struct item *start) state->new = 1; if (!state->reg) { state->u.num.ind = 0; - state->u.num.rev = (state->u.num.min < 0); + if (state->u.num.min < 0) { + while (state->u.num.ind > state->u.num.min) { + state->cur = previtem(state->cur); + --state->u.num.ind; + if (state->cur == state->end) + break; + } + state->end = state->cur; + } } } @@ -147,17 +155,6 @@ findnext(struct search *state) if (state->fin) return NULL; - if (!state->reg && state->u.num.rev) { - while (state->u.num.ind > state->u.num.min) { - state->cur = previtem(state->cur); - --state->u.num.ind; - if (state->cur == state->end) - break; - } - state->u.num.rev = 0; - state->end = state->cur; - } - /* NOTE: state->inc cannot return NULL */ for (match = NULL; !match && !state->fin; state->cur = state->inc(state->cur)) { if (!state->new && state->cur == state->end) { diff --git a/aps/find.h b/aps/find.h @@ -10,7 +10,6 @@ struct search { struct { int ind; int min, max; - int rev, ign; } num; } u; };