(x)memcoll: minor tweaks
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 9 Jul 2010 01:16:40 +0000 (18:16 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 9 Jul 2010 01:24:39 +0000 (18:24 -0700)
* lib/memcoll.c (strcoll_loop): Prefer the style where 'const'
is after the type that it qualifies.
(memcoll0): Likewise.
* lib/memcoll.h (memcoll0): Likewise.
* lib/xmemcoll.c (collate_error, xmemcoll0): Likewise.
* lib/xmemcoll.h (xmemcoll0): Likewise.
* lib/memcoll.c (memcoll0): Correct the comment.  This function
differs from memcoll in that the NUL byte is part of the argument.
Omit the abort-checks, as performance is a real issue here.  Plus,
the checks were wrong anyway (an off-by-one error).  Omit local
variable 'diff', as it's a bit clearer that way.
* m4/memcoll.m4 (gl_MEMCOLL): Omit AC_FUNC_STRCOLL, as it's
no longer needed.

ChangeLog
lib/memcoll.c
lib/memcoll.h
lib/xmemcoll.c
lib/xmemcoll.h
m4/memcoll.m4

index 1577e12aa15e15e41460e20bd7d441a12ce53f93..1207beff4b6f6ea4ce36d3f104156c38428321ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2010-07-08  Paul Eggert  <eggert@cs.ucla.edu>
+
+       (x)memcoll: minor tweaks
+       * lib/memcoll.c (strcoll_loop): Prefer the style where 'const'
+       is after the type that it qualifies.
+       (memcoll0): Likewise.
+       * lib/memcoll.h (memcoll0): Likewise.
+       * lib/xmemcoll.c (collate_error, xmemcoll0): Likewise.
+       * lib/xmemcoll.h (xmemcoll0): Likewise.
+       * lib/memcoll.c (memcoll0): Correct the comment.  This function
+       differs from memcoll in that the NUL byte is part of the argument.
+       Omit the abort-checks, as performance is a real issue here.  Plus,
+       the checks were wrong anyway (an off-by-one error).  Omit local
+       variable 'diff', as it's a bit clearer that way.
+       * m4/memcoll.m4 (gl_MEMCOLL): Omit AC_FUNC_STRCOLL, as it's
+       no longer needed.
+
 2010-07-08  Chen Guo <chenguo4@yahoo.com>
 
        (x)memcoll: speedup when input is known to be NUL delimited
index 8e4855135f12151a0fa93abe3c7751f4912c2c2e..580f81d02b3344983ad44ba702374af857de3486 100644 (file)
    NUL bytes. */
 
 static inline int
-strcoll_loop (const char *s1, size_t s1len, const char *s2, size_t s2len)
+strcoll_loop (char const *s1, size_t s1len, const char *s2, size_t s2len)
 {
   int diff;
+
   while (! (errno = 0, (diff = strcoll (s1, s2)) || errno))
     {
       /* strcoll found no difference, but perhaps it was fooled by NUL
@@ -57,6 +58,7 @@ strcoll_loop (const char *s1, size_t s1len, const char *s2, size_t s2len)
           break;
         }
     }
+
   return diff;
 }
 
@@ -65,7 +67,6 @@ strcoll_loop (const char *s1, size_t s1len, const char *s2, size_t s2len)
    adjacent.  Perhaps temporarily modify the bytes after S1 and S2,
    but restore their original contents before returning.  Set errno to an
    error number if there is an error, and to zero otherwise.  */
-
 int
 memcoll (char *s1, size_t s1len, char *s2, size_t s2len)
 {
@@ -97,24 +98,18 @@ memcoll (char *s1, size_t s1len, char *s2, size_t s2len)
   return diff;
 }
 
-/* Like memcoll, but S1 and S2 are known to be NUL delimited, thus no
-   modification to S1 or S2 are needed. */
+/* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according
+   to the LC_COLLATE locale.  S1 and S2 must both end in a null byte.
+   Set errno to an error number if there is an error, and to zero
+   otherwise.  */
 int
-memcoll0 (const char *s1, size_t s1len, const char *s2, size_t s2len)
+memcoll0 (char const *s1, size_t s1len, const char *s2, size_t s2len)
 {
-  int diff;
-  if (!(s1len > 0 && s1[s1len] == '\0'))
-    abort ();
-  if (!(s2len > 0 && s2[s2len] == '\0'))
-    abort ();
-
   if (s1len == s2len && memcmp (s1, s2, s1len) == 0)
     {
       errno = 0;
-      diff = 0;
+      return 0;
     }
   else
-    diff = strcoll_loop (s1, s1len, s2, s2len);
-
-  return diff;
+    return strcoll_loop (s1, s1len, s2, s2len);
 }
index b43a96e6c37765403309c2d43195a7f28d268c02..1e8ce48481fc4800313a45adcee05545addc086f 100644 (file)
@@ -23,6 +23,6 @@
 # include <stddef.h>
 
 int memcoll (char *, size_t, char *, size_t);
-int memcoll0 (const char *, size_t, const char *, size_t);
+int memcoll0 (char const *, size_t, char const *, size_t);
 
 #endif /* MEMCOLL_H_ */
index 36958f4af494456647e6e2dea99e7636188edc79..7f8c894b055ceccc57d964785d27afa71c799d47 100644 (file)
 #include "quotearg.h"
 #include "xmemcoll.h"
 
-static inline void
-collate_error (int collation_errno, const char *s1, size_t s1len,
-               const char *s2, size_t s2len)
+static void
+collate_error (int collation_errno,
+               char const *s1, size_t s1len,
+               char const *s2, size_t s2len)
 {
   error (0, collation_errno, _("string comparison failed"));
   error (0, 0, _("Set LC_ALL='C' to work around the problem."));
@@ -54,10 +55,8 @@ xmemcoll (char *s1, size_t s1len, char *s2, size_t s2len)
 {
   int diff = memcoll (s1, s1len, s2, s2len);
   int collation_errno = errno;
-
   if (collation_errno)
     collate_error (collation_errno, s1, s1len, s2, s2len);
-
   return diff;
 }
 
@@ -65,11 +64,10 @@ xmemcoll (char *s1, size_t s1len, char *s2, size_t s2len)
    no modifications to S1 and S2 are needed. */
 
 int
-xmemcoll0 (const char *s1, size_t s1len, const char *s2, size_t s2len)
+xmemcoll0 (char const *s1, size_t s1len, char const *s2, size_t s2len)
 {
   int diff = memcoll0 (s1, s1len, s2, s2len);
   int collation_errno = errno;
-
   if (collation_errno)
     collate_error (collation_errno, s1, s1len, s2, s2len);
   return diff;
index b72127dd5495910231a62843447b84db1bdd5a44..4170b9b8dc370d297af781ad774e500726fe18a3 100644 (file)
@@ -1,3 +1,3 @@
 #include <stddef.h>
 int xmemcoll (char *, size_t, char *, size_t);
-int xmemcoll0 (const char *, size_t, const char *, size_t);
+int xmemcoll0 (char const *, size_t, char const *, size_t);
index 0edf30ca42b399a93bc98973d57d31e09ff99098..220b9d3404c49f414f5cf79359b916b58a42392f 100644 (file)
@@ -1,4 +1,4 @@
-# memcoll.m4 serial 7
+# memcoll.m4 serial 8
 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2010 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -9,7 +9,4 @@ AC_DEFUN([gl_MEMCOLL],
 [
   AC_REQUIRE([AC_C_INLINE])
   AC_LIBOBJ([memcoll])
-
-  dnl Prerequisites of lib/memcoll.c.
-  AC_FUNC_STRCOLL
 ])