[darcs-devel] darcs patch: Replace my_memrchr() with strrchr().

Ralph Corderoy ralph at inputplus.co.uk
Mon Apr 18 14:07:38 PDT 2005


Hi David,

> On Mon, Apr 18, 2005 at 09:05:57AM -0400, Ralph Corderoy wrote:
> > Sun Apr 17 23:05:34 BST 2005  Ralph Corderoy <ralph at inputplus.co.uk>
> >   * Replace my_memrchr() with strrchr().
> >   Given it's only ever called on a string, not an arbitrary lump of
> >   memory, my_memrchr() can be replaced with strrchr() which is in
> >   <string.h>.
> 
> I don't think we want to require that this always be called with a
> string, so I'd rather keep the my_memrchr.  If my_memrchr is slower
> than an optimized version, we could easily add configure checks and
> use the real thing if it's available.

Given it's static, there's just one call to it, which is a C string
containing a pathname so that's unlikely to change, and it isn't a hard
function to write I'd still vote for scrapping it now.  It's one less
routine for the reader to parse, and it makes the code that uses it more
familiar too.

The off-chance that a memrchr() might be needed one day doesn't seem
enough to offset all those that will come reading through the file in
the meantime.  If it is added again in the future because memrchr() is
needed rather than strrchr() then that still means the existing call
should be changed to strrchr() now, which leaves my_memchr() uncalled by
anything.

Finally, it reads nicer.

    lastslash = memrchr(p, '/', strlen(p));
    lastslash = strrchr(p, '/');

Cheers,


Ralph.





More information about the darcs-devel mailing list