On Fri, Oct 28, 2011 at 10:05 PM, Alex Rousskov <[email protected]> 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
