Re: [PATCH] HttpHdrSc c++ refactoring: strnrchr

From: Kinkie <gkinkie_at_gmail.com>
Date: Sun, 30 Oct 2011 19:55:47 +0100

On Fri, Oct 28, 2011 at 10:05 PM, Alex Rousskov
<rousskov_at_measurement-factory.com> wrote:
> On 10/28/2011 09:55 AM, Kinkie wrote:
>
>> +/**
>> + * look for the last occurrence of a character in a c-string with a set maximum length
>> + */
>> +SQUIDCEXTERN const char *strnrchr(const char *s, size_t slen, char c);
>> +
>
> "Maximum c-string length" oxymoron allows for at least two very
> different interpretations as illustrated below:
>
> Your strnrchr() implementation implies the following specs: "find the
> last character c before the end of the string or slen-th string
> character, whichever comes first". These specs costs a lot of wasted
> cycles in most cases because you have to start looking from the
> beginning of the string and check for null character at each position.
> However, the actual use in the patch implies we can just use memrchr()
> instead, which is much more efficient, of course.

Yes. I chose the safe route and took inspiration from the TODO comment.
Now reverted to memrchr, relying on <cstring> - I'm not sure memrchr
is part of ISO C.

> Can we just use memrchr() instead (and provide it if it is not available)?
>
>
>> +        if (!((target = strnrchr (item, initiallen+1, ';')) && ...
>
> Why are we adding 1 in the above strnrchr() call? Does not the item have
> no more than initiallen characters?

Direct porting; in short, I don't know.

-- 
    /kinkie
Received on Sun Oct 30 2011 - 18:55:55 MDT

This archive was generated by hypermail 2.2.0 : Tue Nov 01 2011 - 12:00:10 MDT