coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coreutils] [PATCH] sort: fix --debug display with very large offset


From: Eric Blake
Subject: Re: [coreutils] [PATCH] sort: fix --debug display with very large offsets
Date: Tue, 27 Jul 2010 14:29:37 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Fedora/3.1.1-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.3 Thunderbird/3.1.1

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   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]