[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0385c0c0820 1/2: (buf_*pos_to_*pos): Fix minor off-by one
From: |
Stefan Monnier |
Subject: |
master 0385c0c0820 1/2: (buf_*pos_to_*pos): Fix minor off-by one |
Date: |
Tue, 2 Jul 2024 16:29:33 -0400 (EDT) |
branch: master
commit 0385c0c0820361b71a74988f23d0445238f30473
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
(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.
---
src/marker.c | 44 ++++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/src/marker.c b/src/marker.c
index 9aaa2e7402c..16fa3bcef3e 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -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.