tabs: compute the number of required spaces without iterating

This commit is contained in:
Benno Schulenberg 2016-06-24 10:17:06 +02:00
parent 1a4ec6c2d3
commit 68acc1dfc5

View File

@ -247,25 +247,18 @@ void do_tab(void)
{
#ifndef NANO_TINY
if (ISSET(TABS_TO_SPACES)) {
char *output;
size_t output_len = 0, new_pww = xplustabs();
char *spaces = charalloc(tabsize + 1);
size_t length = tabsize - (xplustabs() % tabsize);
do {
new_pww++;
output_len++;
} while (new_pww % tabsize != 0);
charset(spaces, ' ', length);
spaces[length] = '\0';
output = charalloc(output_len + 1);
do_output(spaces, length, TRUE);
charset(output, ' ', output_len);
output[output_len] = '\0';
do_output(output, output_len, TRUE);
free(output);
free(spaces);
} else
#endif
do_output((char *) "\t", 1, TRUE);
do_output((char *)"\t", 1, TRUE);
}
#ifndef NANO_TINY