changeset 13453:c5416617cfbf

(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.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 08 Jul 2010 18:16:40 -0700
parents edb3fc126c07
children 24850bb5c424
files ChangeLog lib/memcoll.c lib/memcoll.h lib/xmemcoll.c lib/xmemcoll.h m4/memcoll.m4
diffstat 6 files changed, 35 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- 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
--- a/lib/memcoll.c
+++ b/lib/memcoll.c
@@ -30,9 +30,10 @@
    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 @@
           break;
         }
     }
+
   return diff;
 }
 
@@ -65,7 +67,6 @@
    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 @@
   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);
 }
--- a/lib/memcoll.h
+++ b/lib/memcoll.h
@@ -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_ */
--- a/lib/xmemcoll.c
+++ b/lib/xmemcoll.c
@@ -31,9 +31,10 @@
 #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 @@
 {
   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 @@
    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;
--- a/lib/xmemcoll.h
+++ b/lib/xmemcoll.h
@@ -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);
--- a/m4/memcoll.m4
+++ b/m4/memcoll.m4
@@ -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_REQUIRE([AC_C_INLINE])
   AC_LIBOBJ([memcoll])
-
-  dnl Prerequisites of lib/memcoll.c.
-  AC_FUNC_STRCOLL
 ])