[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 70x speed-up for seq's common cases
From: |
Bernhard Voelker |
Subject: |
Re: 70x speed-up for seq's common cases |
Date: |
Fri, 14 Sep 2012 10:48:32 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 |
On 09/14/2012 10:40 AM, Jim Meyering wrote:
> Bernhard Voelker wrote:
>> Shouldn't we free(buf), too?
>
> Thanks.
> Yes, to placate leak-checking tools, but for the record, any time buf
> was allocated, we'd exit (successfully) right after return from that
> function.
>
> Hence, I've added the free guarded by IF_LINT:
>
> @@ -429,7 +429,7 @@ seq_fast (char const *a, char const *b)
> if (buf < z)
> fwrite (buf, z - buf, 1, stdout);
>
> + IF_LINT (free (buf));
> }
The other 2 calls to free() could then also be IF_LINT()ed.
>>> @@ -412,6 +520,33 @@ main (int argc, char **argv)
>>
>>> [...]
>>
>>> + if (format_str == NULL
>>> + && all_digits_p (argv[1])
>>> + && (n_args == 1 || all_digits_p (argv[2]))
>>> + && (n_args < 3 || STREQ ("1", argv[3])))
>>> + {
>>> + char const *s1 = n_args == 1 ? "1" : argv[1];
>>> + char const *s2 = n_args == 1 ? argv[1] : argv[2];
>>> + if (seq_fast (s1, s2))
>>> + exit (EXIT_SUCCESS);
>>> +
>>> + /* Upon any failure, let the more general code deal with it. */
>>> + }
>>
>> seq_fast can only return ok.
>
> True, but "ok" can be false ;-)
> I.e., with out of order arguments:
>
> seq 9 1
ah, right. I was tricked by the variable name ;-)
>> BTW:
>> src/seq.c: In function 'all_digits_p':
>> src/seq.c:440:1: error: function might be candidate for attribute
>> pure' if it is known to return normally
>> [-Werror=suggest-attribute=pure]
>>
>> Therefore:
>> -static bool
>> +static bool _GL_ATTRIBUTE_PURE
>> all_digits_p (char const *s)
>
> Oh! Thank you.
> Why didn't gcc 4.8.0 20120912 tell me that one?
I don't know, mine is gcc 4.6.2.
Have a nice day,
Berny