"Richard L. Hamilton" <[EMAIL PROTECTED]> wrote: > Jörg wrote: > > I believe that strnlen is something like: > > > > p2 = memchr(p, o, len); > > if (p == 0 || p2 - p > len) > > return (len); > > return (p2 - p); > > > > Why do you like to start with strlen()? > > What you posted resembles (although is not identical to) an LGPL > implementation*, and > str*() functions don't typically need to check for a NULL pointer (p == 0). > I wanted to be
OOPs, this should be if (p2 == 0 || p2 - p > len) which is needed in case that there is no '\0'. > sure the provenance was ok. Also Casper said that there's no platform > optimized versions of memchr() anyway, and I usually take it for granted that > he's > _Right_ (although checking now, I do see platform-specific assembler versions > of > memchr() that look like they'd be a good bit faster than my code, which in > turn means > your code is faster than mine, at least for strings of more than a very few > characters). > > Object lession: some of the unused (in favor of platform-specific versions) > "portable" > functions in libc/port/gen are seriously (and historically) _lame_ in terms > of performance, > and may constitute rather poor examples. Noted... It is possible to write a portable and fast version of memchr. Check e.g. findbytes.c in the cdrtools source: ftp://ftp.berlios.de/pub/cdrecord/alpha/ Jörg -- EMail:[EMAIL PROTECTED] (home) Jörg Schilling D-13353 Berlin [EMAIL PROTECTED] (uni) [EMAIL PROTECTED] (work) Blog: http://schily.blogspot.com/ URL: http://cdrecord.berlios.de/old/private/ ftp://ftp.berlios.de/pub/schily _______________________________________________ opensolaris-code mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
