Mercurial > hg > octave-lyh > gnulib-hg
changeset 9544:ae875e538d30
Use GNU style coding conventions.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 26 Dec 2007 16:13:28 +0100 |
parents | 42242ade9225 |
children | c596ca4e89b4 |
files | ChangeLog lib/memmem.c |
diffstat | 2 files changed, 56 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-23 Bruno Haible <bruno@clisp.org> + + * lib/memmem.c (memmem): Use lowercase variable names. Tab + indentation. + 2007-12-23 Bruno Haible <bruno@clisp.org> * lib/c-strcasestr.c: Add more comments.
--- a/lib/memmem.c +++ b/lib/memmem.c @@ -154,14 +154,14 @@ 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 @@ /* 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 @@ /* 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; + 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; - } - } + /* 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; + 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; - } - } + 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; + } + } } }