m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

use memchr2


From: Eric Blake
Subject: use memchr2
Date: Thu, 19 Mar 2009 22:23:49 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bruno recently added memchr2 to gnulib, and I like it.  Applied to
branch-1.6, and soon to follow on master (branch-1.4 doesn't need it,
because it doesn't handle NUL very well to begin with).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknDGlUACgkQ84KuGfSFAYBEJACfZOFHVDZzRkGduUELfG+DHG5J
gTEAoMQWg1axN43aZXSQuOI9A1VhA2Br
=LJw5
-----END PGP SIGNATURE-----
>From d7f708504fc66d0bcd35b60c1a5143c39197c8eb Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 19 Mar 2009 13:51:31 -0600
Subject: [PATCH] Use memcmp2 to simplify lexicographic comparisons.

* m4/gnulib-cache.m4: Import memcmp2.
* src/builtin.c (dumpdef_cmp): Use it.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog          |    6 ++++++
 m4/gnulib-cache.m4 |    3 ++-
 src/builtin.c      |   10 +++-------
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 60f51ad..21ebe14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-19  Eric Blake  <address@hidden>
+
+       Use memcmp2 to simplify lexicographic comparisons.
+       * m4/gnulib-cache.m4: Import memcmp2.
+       * src/builtin.c (dumpdef_cmp): Use it.
+
 2009-03-13  Eric Blake  <address@hidden>

        Fix testsuite failure on mingw.
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index 3043f85..d749cdb 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@


 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=local --lib=libm4 
--source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests 
--aux-dir=build-aux --with-tests --no-libtool --macro-prefix=M4 announce-gen 
assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein 
config-h dirname error execute fdl-1.3 fflush filenamecat flexmember fopen 
fopen-safer freadptr freadseek fseeko gendocs getopt git-version-gen 
gnumakefile gnupload gpl-3.0 hash intprops memchr2 memmem mkstemp obstack 
obstack-printf-posix pipe progname quote regex stdbool stdint stdlib-safer 
strtod strtol unlocked-io vasnprintf-posix verror version-etc version-etc-fsf 
wait-process xalloc xmemdup0 xprintf xvasprintf-posix
+#   gnulib-tool --import --dir=. --local-dir=local --lib=libm4 
--source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests 
--aux-dir=build-aux --with-tests --no-libtool --macro-prefix=M4 announce-gen 
assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein 
config-h dirname error execute fdl-1.3 fflush filenamecat flexmember fopen 
fopen-safer freadptr freadseek fseeko gendocs getopt git-version-gen 
gnumakefile gnupload gpl-3.0 hash intprops memchr2 memcmp2 memmem mkstemp 
obstack obstack-printf-posix pipe progname quote regex stdbool stdint 
stdlib-safer strtod strtol unlocked-io vasnprintf-posix verror version-etc 
version-etc-fsf wait-process xalloc xmemdup0 xprintf xvasprintf-posix

 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([local])
@@ -51,6 +51,7 @@ gl_MODULES([
   hash
   intprops
   memchr2
+  memcmp2
   memmem
   mkstemp
   obstack
diff --git a/src/builtin.c b/src/builtin.c
index 0062ca0..a28535b 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -26,6 +26,7 @@

 #include "execute.h"
 #include "memchr2.h"
+#include "memcmp2.h"
 #include "pipe.h"
 #include "regex.h"
 #include "wait-process.h"
@@ -864,13 +865,8 @@ dumpdef_cmp (const void *s1, const void *s2)
 {
   const symbol *sym1 = *(const symbol **) s1;
   const symbol *sym2 = *(const symbol **) s2;
-  size_t len1 = SYMBOL_NAME_LEN (sym1);
-  size_t len2 = SYMBOL_NAME_LEN (sym2);
-  int result = memcmp (SYMBOL_NAME (sym1), SYMBOL_NAME (sym2),
-                      len1 < len2 ? len1 : len2);
-  if (!result)
-    result = len1 < len2 ? -1 : len2 < len1;
-  return result;
+  return memcmp2 (SYMBOL_NAME (sym1), SYMBOL_NAME_LEN (sym1),
+                  SYMBOL_NAME (sym2), SYMBOL_NAME_LEN (sym2));
 }

 /*-------------------------------------------------------------------------.
-- 
1.6.1.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]