This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Optimize strchr (x, 0)


On Sun, Feb 24, 2013 at 12:39:48PM +0100, Andreas Schwab wrote:
> OndÅej BÃlka <neleai@seznam.cz> writes:
> 
> > +		       : (*((char *) __mempcpy (stplen (__dest),	      \
> 
> __stplen
> 
> Andreas.
> 
> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."

Thanks, here is updated version.

I forgot to mention that to apply this patch Use-BUILTIN_SINCE_GCC_3_2-macro 
patch must be applied first.

	* string/bits/string2.h: Add stplen macro.
	(rawmemchr) Optimize case rawmemchr(x, 0).
	(strchr) Use stplen.
	(strcat) Likewise.

---
 string/bits/string2.h |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/string/bits/string2.h b/string/bits/string2.h
index f452bce..42acd2a 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -28,6 +28,12 @@
 # define __BUILTIN_SINCE_GCC_3_2(fn) fn
 #endif
 
+#define __stplen(s) \
+  (__extension__ ({ char *__s = (char *) (s);				      \
+		    __s + strlen (__s); }))
+
+
+
 #ifndef __NO_STRING_INLINES
 
/* Unlike the definitions in the header <bits/string.h> the
@@ -401,10 +407,19 @@ __mempcpy_small (void *__dest, char __src1,
 extern void *__rawmemchr (const void *__s, int __c);
 # define strchr(s, c) \
   (__extension__ (__builtin_constant_p (c) && (c) == '\0'		      \
-		  ? (char *) __rawmemchr (s, c)				      \
+		  ? __stplen (s)					      \
 		  : __BUILTIN_SINCE_GCC_3_2 (strchr) (s, c)))
 #endif
 
+#ifndef _HAVE_STRING_ARCH_rawmemchr
+# define __rawmemchr(s, c) \
+  (__extension__ (__builtin_constant_p (c) && (c) == '\0'		      \
+		  ? __stplen (s)					      \
+		  : __rawmemchr (s, c)))
+#endif
+
+
+
 
 /* Copy SRC to DEST.  */
 #if (!defined _HAVE_STRING_ARCH_strcpy && !__GNUC_PREREQ (3, 0)) \
@@ -777,7 +792,7 @@ __stpcpy_small (char *__dest,
 		    __builtin_constant_p (src) && __builtin_constant_p (n)    \
 		    ? (strlen (src) < ((size_t) (n))			      \
 		       ? strcat (__dest, src)				      \
-		       : (*((char *) __mempcpy (strchr (__dest, '\0'),	      \
+		       : (*((char *) __mempcpy (__stplen (__dest),	      \
 						src, n)) = '\0', __dest))     \
 		    : strncat (dest, src, n); }))
 # elif __GNUC_PREREQ (3, 2)
-- 
1.7.4.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]