Commit 8993c363 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: reduce the number of additions that actual_x() performs

Replace them by a single subtraction.
No related merge requests found
Showing with 4 additions and 5 deletions
+4 -5
...@@ -392,10 +392,10 @@ size_t xplustabs(void) ...@@ -392,10 +392,10 @@ size_t xplustabs(void)
* not overshoot the given column. */ * not overshoot the given column. */
size_t actual_x(const char *text, size_t column) size_t actual_x(const char *text, size_t column)
{ {
size_t index = 0; const char *start = text;
/* The index in text, returned. */ /* From where we start walking through the text. */
size_t width = 0; size_t width = 0;
/* The screen display width to text[index], in columns. */ /* The current accumulated span, in columns. */
while (*text != '\0') { while (*text != '\0') {
int charlen = parse_mbchar(text, NULL, &width); int charlen = parse_mbchar(text, NULL, &width);
...@@ -403,11 +403,10 @@ size_t actual_x(const char *text, size_t column) ...@@ -403,11 +403,10 @@ size_t actual_x(const char *text, size_t column)
if (width > column) if (width > column)
break; break;
index += charlen;
text += charlen; text += charlen;
} }
return index; return (text - start);
} }
/* A strnlen() with tabs and multicolumn characters factored in: /* A strnlen() with tabs and multicolumn characters factored in:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment