From: Bruno Haible Date: Wed, 26 Dec 2007 15:13:28 +0000 (+0100) Subject: Use GNU style coding conventions. X-Git-Tag: v0.1~7909 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=4a64397b5b568bf0e6c0e4a41e5d98dd7352b0d4;p=gnulib.git Use GNU style coding conventions. --- diff --git a/ChangeLog b/ChangeLog index 0578cf86c..4b558a36f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-12-23 Bruno Haible + * lib/memmem.c (memmem): Use lowercase variable names. Tab + indentation. + +2007-12-23 Bruno Haible + * lib/c-strcasestr.c: Add more comments. * lib/c-strstr.c: Likewise. * lib/mbscasestr.c: Likewise. diff --git a/lib/memmem.c b/lib/memmem.c index ae2c6ee93..58f95f73b 100644 --- a/lib/memmem.c +++ b/lib/memmem.c @@ -154,14 +154,14 @@ knuth_morris_pratt (const char *haystack, const char *last_haystack, if NEEDLE_LEN is 0, otherwise NULL if NEEDLE is not found in HAYSTACK. */ void * -memmem (const void *haystack, size_t haystack_len, - const void *needle, size_t needle_len) +memmem (const void *haystack_start, size_t haystack_len, + const void *needle_start, size_t needle_len) { /* Operating with void * is awkward. */ - const char *Haystack = (const char *) haystack; - const char *Needle = (const char *) needle; - const char *last_haystack = Haystack + haystack_len; - const char *last_needle = Needle + needle_len; + const char *haystack = (const char *) haystack_start; + const char *needle = (const char *) needle_start; + const char *last_haystack = haystack + haystack_len; + const char *last_needle = needle + needle_len; if (needle_len == 0) /* The first occurrence of the empty string is deemed to occur at @@ -175,7 +175,7 @@ memmem (const void *haystack, size_t haystack_len, /* Use optimizations in memchr when possible. */ if (__builtin_expect (needle_len == 1, 0)) - return memchr (haystack, (unsigned char) *Needle, haystack_len); + return memchr (haystack, (unsigned char) *needle, haystack_len); /* Minimizing the worst-case complexity: Let n = haystack_len, m = needle_len. @@ -198,55 +198,55 @@ memmem (const void *haystack, size_t haystack_len, /* Speed up the following searches of needle by caching its first byte. */ - char b = *Needle++; + char b = *needle++; - for (;; Haystack++) + for (;; haystack++) { - if (Haystack == last_haystack) - /* No match. */ - return NULL; - - /* See whether it's advisable to use an asymptotically faster - algorithm. */ - if (try_kmp - && outer_loop_count >= 10 - && comparison_count >= 5 * outer_loop_count) - { - /* See if needle + comparison_count now reaches the end of - needle. */ - if (comparison_count >= needle_len) - { - /* Try the Knuth-Morris-Pratt algorithm. */ - const char *result; - if (knuth_morris_pratt (Haystack, last_haystack, - Needle - 1, needle_len, &result)) - return (void *) result; - try_kmp = false; - } - } - - outer_loop_count++; - comparison_count++; - if (*Haystack == b) - /* The first byte matches. */ - { - const char *rhaystack = Haystack + 1; - const char *rneedle = Needle; - - for (;; rhaystack++, rneedle++) - { - if (rneedle == last_needle) - /* Found a match. */ - return (void *) Haystack; - if (rhaystack == last_haystack) - /* No match. */ - return NULL; - comparison_count++; - if (*rhaystack != *rneedle) - /* Nothing in this round. */ - break; - } - } + if (haystack == last_haystack) + /* No match. */ + return NULL; + + /* See whether it's advisable to use an asymptotically faster + algorithm. */ + if (try_kmp + && outer_loop_count >= 10 + && comparison_count >= 5 * outer_loop_count) + { + /* See if needle + comparison_count now reaches the end of + needle. */ + if (comparison_count >= needle_len) + { + /* Try the Knuth-Morris-Pratt algorithm. */ + const char *result; + if (knuth_morris_pratt (haystack, last_haystack, + needle - 1, needle_len, &result)) + return (void *) result; + try_kmp = false; + } + } + + outer_loop_count++; + comparison_count++; + if (*haystack == b) + /* The first byte matches. */ + { + const char *rhaystack = haystack + 1; + const char *rneedle = needle; + + for (;; rhaystack++, rneedle++) + { + if (rneedle == last_needle) + /* Found a match. */ + return (void *) haystack; + if (rhaystack == last_haystack) + /* No match. */ + return NULL; + comparison_count++; + if (*rhaystack != *rneedle) + /* Nothing in this round. */ + break; + } + } } }