[PATCH RESEND] libbb: shrink is_suffixed_with() function
Tito
farmatito at tiscali.it
Tue Sep 15 20:04:28 UTC 2015
Hi,
can you apply the additional test case?
Ciao,
Tito
On 09/15/2015 07:56 PM, Denys Vlasenko wrote:
> On Sun, Sep 13, 2015 at 8:07 AM, Tito <farmatito at tiscali.it> wrote:
>> attached you will find a patch that shrinks the is_suffixed_with
>> function and adds one more test case as suggested by Bartosz
>> Golaszewski.
>>
>> Bloat-o-meter says:
>>
>> function old new delta
>> is_suffixed_with 83 47 -36
>> ------------------------------------------------------------------------------
>> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36) Total: -36 bytes
>
>> char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
>> {
>> - size_t key_len = strlen(key);
>> - ssize_t len_diff = strlen(string) - key_len;
>> -
>> - if (len_diff >= 0) {
>> - string += len_diff;
>> - if (strcmp(string, key) == 0) {
>> - return (char*)string;
>> - }
>> - }
>> -
>> + char *s = strrstr(string, key);
>> + if (s && strcmp(s, key) == 0)
>> + return s;
>> return NULL;
>
> This version is too performance-pessimized.
>
More information about the busybox
mailing list