[Top][All Lists]

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

rawmemchr usage

From: Eric Blake
Subject: rawmemchr usage
Date: Tue, 26 May 2009 19:26:09 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I did a quick audit of all uses of memchr, considering that there is a proposal 
to un-obsolete the memchr module now that we have identified glibc bugs in 
platform-specific implementations for two different platforms.  The choice of 
whether to beef up the memchr module depends on whether or not we consider the 
glibc bugs too short-lived to be worth worrying about.  The only use of memchr 
where the module does not already call out the dependency is vasnprintf.

But while grepping for 'memchr', I noticed that strtok_r was using #define 
__rawmemchr strchr.  This stems from the days prior to the gnulib 
implementation of rawmemchr; is it worth applying this patch for a slight 
speedup to strtok_r?  Or is the platform-specific assembly version of strchr 
likely to be as efficient as the C-coded rawmemchr replacement on platforms 
that lack rawmemchr, such that it is not worth the extra dependency?

Likewise, what about these other modules that only use strchr to find the 
terminating byte of a known-terminated string, where rawmemchr could be the 
faster choice?

lib/argz.c:     entry = strchr (entry, '\0') + 1;
lib/argz.in.h:  __entry = strchr (__entry, '\0') + 1;
lib/canonicalize-lgpl.c:      dest = strchr (rpath, '\0');
lib/canonicalize.c:      dest = strchr (rname, '\0');
lib/glob.c:                 end_name = strchr (unescape, '\0');

From: Eric Blake <address@hidden>
Date: Tue, 26 May 2009 12:21:17 -0600
Subject: [PATCH] strtok_r: use rawmemchr for speed.

* lib/strtok_r.c (__rawmemchr): Use faster rawmemchr.
* modules/strtok_r (Depends-on): Add rawmemchr.

Signed-off-by: Eric Blake <address@hidden>
 ChangeLog        |    4 ++++
 lib/strtok_r.c   |    4 ++--
 modules/strtok_r |    1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c930b7b..c42c23f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-05-26  Eric Blake  <address@hidden>

+       strtok_r: use rawmemchr for speed.
+       * lib/strtok_r.c (__rawmemchr): Use faster rawmemchr.
+       * modules/strtok_r (Depends-on): Add rawmemchr.
        memchr: detect broken x86_64 and alpha implementations
        * modules/memchr-tests (Depends-on): Move mmap detection...
        * modules/memchr (Depends-on): ...here.
diff --git a/lib/strtok_r.c b/lib/strtok_r.c
index 232474a..562e727 100644
--- a/lib/strtok_r.c
+++ b/lib/strtok_r.c
@@ -1,5 +1,5 @@
 /* Reentrant string tokenizer.  Generic version.
-   Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
+   Copyright (C) 1991,1996-1999,2001,2004,2007,2009 Free Software Foundation, 
    This file is part of the GNU C Library.

    This program is free software: you can redistribute it and/or modify
@@ -26,7 +26,7 @@

 #ifndef _LIBC
 # define __strtok_r strtok_r
-# define __rawmemchr strchr
+# define __rawmemchr rawmemchr

 /* Parse S into tokens separated by characters in DELIM.
diff --git a/modules/strtok_r b/modules/strtok_r
index f638baa..d960cfe 100644
--- a/modules/strtok_r
+++ b/modules/strtok_r
@@ -8,6 +8,7 @@ m4/strtok_r.m4


reply via email to

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