From 8993c363666390d9a4ce677a57b358217753d1b8 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Mon, 10 Apr 2017 19:25:40 +0200
Subject: [PATCH] tweaks: reduce the number of additions that actual_x()
 performs

Replace them by a single subtraction.
---
 src/utils.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/utils.c b/src/utils.c
index 8f1ebf79..fe486609 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -392,10 +392,10 @@ size_t xplustabs(void)
  * not overshoot the given column. */
 size_t actual_x(const char *text, size_t column)
 {
-    size_t index = 0;
-	/* The index in text, returned. */
+    const char *start = text;
+	/* From where we start walking through the text. */
     size_t width = 0;
-	/* The screen display width to text[index], in columns. */
+	/* The current accumulated span, in columns. */
 
     while (*text != '\0') {
 	int charlen = parse_mbchar(text, NULL, &width);
@@ -403,11 +403,10 @@ size_t actual_x(const char *text, size_t column)
 	if (width > column)
 	    break;
 
-	index += charlen;
 	text += charlen;
     }
 
-    return index;
+    return (text - start);
 }
 
 /* A strnlen() with tabs and multicolumn characters factored in:
-- 
GitLab