(buf_*pos_to_*pos): Fix minor off-by one

* src/marker.c (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Slightly restructure the markers loop so we check `distance`
also before "consider"ing the first marker.
This commit is contained in:
Stefan Monnier 2024-07-02 16:28:08 -04:00
parent 4c3e0c990c
commit 0385c0c082

View file

@ -202,19 +202,15 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff)
CONSIDER (cached_charpos, cached_bytepos);
for (tail = BUF_MARKERS (b); tail; tail = tail->next)
{
CONSIDER (tail->charpos, tail->bytepos);
/* If we are down to a range of 50 chars,
don't bother checking any other markers;
scan the intervening chars directly now. */
if (best_above - charpos < distance
|| charpos - best_below < distance)
break;
else
distance += BYTECHAR_DISTANCE_INCREMENT;
}
for (tail = BUF_MARKERS (b);
/* If we are down to a range of DISTANCE chars,
don't bother checking any other markers;
scan the intervening chars directly now. */
tail && !(best_above - charpos < distance
|| charpos - best_below < distance);
tail = tail->next,
distance += BYTECHAR_DISTANCE_INCREMENT)
CONSIDER (tail->charpos, tail->bytepos);
/* We get here if we did not exactly hit one of the known places.
We have one known above and one known below.
@ -354,19 +350,15 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff)
CONSIDER (cached_bytepos, cached_charpos);
for (tail = BUF_MARKERS (b); tail; tail = tail->next)
{
CONSIDER (tail->bytepos, tail->charpos);
/* If we are down to a range of DISTANCE bytes,
don't bother checking any other markers;
scan the intervening chars directly now. */
if (best_above_byte - bytepos < distance
|| bytepos - best_below_byte < distance)
break;
else
distance += BYTECHAR_DISTANCE_INCREMENT;
}
for (tail = BUF_MARKERS (b);
/* If we are down to a range of DISTANCE bytes,
don't bother checking any other markers;
scan the intervening chars directly now. */
tail && !(best_above_byte - bytepos < distance
|| bytepos - best_below_byte < distance);
tail = tail->next,
distance += BYTECHAR_DISTANCE_INCREMENT)
CONSIDER (tail->bytepos, tail->charpos);
/* We get here if we did not exactly hit one of the known places.
We have one known above and one known below.