On 07/27/2010 12:03 PM, Paul Eggert wrote:
> * src/sort.c (mark_key): Don't assume offset <= INT_MAX.
> Make the code a bit clearer when width != 0.
> ---
> src/sort.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/sort.c b/src/sort.c
> index 588bae8..f552d21 100644
> --- a/src/sort.c
> +++ b/src/sort.c
> @@ -2162,14 +2162,17 @@ count_tabs (char const *text, size_t len)
> static void
> mark_key (size_t offset, size_t width)
> {
> - printf ("%*s", (int) offset, "");
> + while (offset--)
> + putchar (' ');
Ouch - this is quite slow for large offset, based on the extremely large
number of function calls it introduces (putchar is particularly bad, if
it is on a system where the gnulib unlocked-io module was not able to
replace it with putchar_unlocked, because of the locking and unlocking
it must do on every call).
I'd rather see something along the lines of:
while (INT_MAX < offset)
{
printf ("%*s", INT_MAX, "");
offset -= INT_MAX;
}
printf ("%*s", (int) offset), "");
so that the common case is back to a single function call.
--
Eric Blake [email protected] +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
