This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On 06/28/2012 08:00 AM, Eric Blake wrote: > On 05/30/2012 03:11 AM, Maxim Kuvyrkov wrote: >> [PATCH 3/4] Use pointers for traversing arrays in strstr, strcasestr and memmem. >> >> -- >> Maxim Kuvyrkov >> CodeSourcery / Mentor Graphics >> >> >> * string/str-two-way.h (two_way_short_needle): Use pointers instead of >> array references. >> * string/strcasestr.c (TOLOWER): Make side-effect safe. > >> +++ b/string/strcasestr.c >> @@ -36,7 +36,7 @@ >> #include <stdbool.h> >> #include <strings.h> >> >> -#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) >> +#define TOLOWER(Ch) tolower (Ch) > > This optimization may work for glibc, but it violates POSIX. I intended > for the C implementation of strcasestr to be copied to other platforms > (that is, gnulib intends to sync with glibc, and gnulib compiles this > file as a replacement on other platforms where libc's strcasestr is > sub-optimal). For me to ack this part of the patch, you will need to > use preprocessor guards to validate that you are compiling against a > version of tolower() that has stronger guarantees about behavior than > what POSIX states about out-of-range input. Correcting myself, after re-reading POSIX: I was thinking of _tolower(), not tolower(), as the function that POSIX says has a limited input range. If we accept that the cost of isupper() is necessary, then we should be using _tolower() for speed. On the other hand, using tolower() in isolation should be about the same as using isupper() to pre-filter whether _tolower() is safe. So I think this optimization is safe, after all. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |