Use GNU style coding conventions.
authorBruno Haible <bruno@clisp.org>
Wed, 26 Dec 2007 15:13:28 +0000 (16:13 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 26 Dec 2007 15:13:28 +0000 (16:13 +0100)
ChangeLog
lib/memmem.c

index 0578cf8..4b558a3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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.
        * lib/c-strstr.c: Likewise.
        * lib/mbscasestr.c: Likewise.
index ae2c6ee..58f95f7 100644 (file)
@@ -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;
+             }
+         }
       }
   }