Commit 68acc1df authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tabs: compute the number of required spaces without iterating

parent 1a4ec6c2
Showing with 7 additions and 14 deletions
+7 -14
...@@ -247,25 +247,18 @@ void do_tab(void) ...@@ -247,25 +247,18 @@ void do_tab(void)
{ {
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(TABS_TO_SPACES)) { if (ISSET(TABS_TO_SPACES)) {
char *output; char *spaces = charalloc(tabsize + 1);
size_t output_len = 0, new_pww = xplustabs(); size_t length = tabsize - (xplustabs() % tabsize);
do {
new_pww++;
output_len++;
} while (new_pww % tabsize != 0);
output = charalloc(output_len + 1); charset(spaces, ' ', length);
spaces[length] = '\0';
charset(output, ' ', output_len); do_output(spaces, length, TRUE);
output[output_len] = '\0';
do_output(output, output_len, TRUE); free(spaces);
free(output);
} else } else
#endif #endif
do_output((char *) "\t", 1, TRUE); do_output((char *)"\t", 1, TRUE);
} }
#ifndef NANO_TINY #ifndef NANO_TINY
......
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