This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] refactor strspn/strcspn macro
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Wed, 16 Jan 2013 13:58:14 +0100
- Subject: [PATCH] refactor strspn/strcspn macro
In header strspn/strcspn define two nearly identical versions of macro
that differ on using builtins. This reduces cost of updating it.
OK to commit?
In string/bits/string2.h there are other macros that could be simplified
in same way.
Ondra
* string/bits/string2.h(strspn,strcspn): Simplify macro
---
string/bits/string2.h | 65 ++++++++++++++++---------------------------------
1 files changed, 21 insertions(+), 44 deletions(-)
diff --git a/string/bits/string2.h b/string/bits/string2.h
index ef1fca3..65ecefd 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -931,12 +931,16 @@ __stpcpy_small (char *__dest,
#if !defined _HAVE_STRING_ARCH_strcspn || defined _FORCE_INLINES
# ifndef _HAVE_STRING_ARCH_strcspn
# if __GNUC_PREREQ (3, 2)
-# define strcspn(s, reject) \
+# define __b_strcspn __builtin_strcspn
+# else
+# define __b_strcspn strcspn
+# endif
+# define strcspn(s, reject) \
__extension__ \
({ char __r0, __r1, __r2; \
(__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
? ((__builtin_constant_p (s) && __string2_1bptr_p (s)) \
- ? __builtin_strcspn (s, reject) \
+ ? __b_strcspn (s, reject) \
: ((__r0 = ((const char *) (reject))[0], __r0 == '\0') \
? strlen (s) \
: ((__r1 = ((const char *) (reject))[1], __r1 == '\0') \
@@ -945,24 +949,8 @@ __stpcpy_small (char *__dest,
? __strcspn_c2 (s, __r0, __r1) \
: (((const char *) (reject))[3] == '\0' \
? __strcspn_c3 (s, __r0, __r1, __r2) \
- : __builtin_strcspn (s, reject)))))) \
- : __builtin_strcspn (s, reject)); })
-# else
-# define strcspn(s, reject) \
- __extension__ \
- ({ char __r0, __r1, __r2; \
- (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \
- ? ((__r0 = ((const char *) (reject))[0], __r0 == '\0') \
- ? strlen (s) \
- : ((__r1 = ((const char *) (reject))[1], __r1 == '\0') \
- ? __strcspn_c1 (s, __r0) \
- : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \
- ? __strcspn_c2 (s, __r0, __r1) \
- : (((const char *) (reject))[3] == '\0' \
- ? __strcspn_c3 (s, __r0, __r1, __r2) \
- : strcspn (s, reject))))) \
- : strcspn (s, reject)); })
-# endif
+ : __b_strcspn (s, reject)))))) \
+ : __b_strcspn (s, reject)); })
# endif
__STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject);
@@ -1007,12 +995,16 @@ __strcspn_c3 (const char *__s, int __reject1, int __reject2,
#if !defined _HAVE_STRING_ARCH_strspn || defined _FORCE_INLINES
# ifndef _HAVE_STRING_ARCH_strspn
# if __GNUC_PREREQ (3, 2)
-# define strspn(s, accept) \
+# define __b_strspn __builtin_strspn
+# else
+# define __b_strspn strspn
+# endif
+# define strspn(s, accept) \
__extension__ \
({ char __a0, __a1, __a2; \
(__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
? ((__builtin_constant_p (s) && __string2_1bptr_p (s)) \
- ? __builtin_strspn (s, accept) \
+ ? __b_strspn (s, accept) \
: ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
? ((void) (s), (size_t) 0) \
: ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
@@ -1021,24 +1013,8 @@ __strcspn_c3 (const char *__s, int __reject1, int __reject2,
? __strspn_c2 (s, __a0, __a1) \
: (((const char *) (accept))[3] == '\0' \
? __strspn_c3 (s, __a0, __a1, __a2) \
- : __builtin_strspn (s, accept)))))) \
- : __builtin_strspn (s, accept)); })
-# else
-# define strspn(s, accept) \
- __extension__ \
- ({ char __a0, __a1, __a2; \
- (__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
- ? ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
- ? ((void) (s), (size_t) 0) \
- : ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
- ? __strspn_c1 (s, __a0) \
- : ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
- ? __strspn_c2 (s, __a0, __a1) \
- : (((const char *) (accept))[3] == '\0' \
- ? __strspn_c3 (s, __a0, __a1, __a2) \
- : strspn (s, accept))))) \
- : strspn (s, accept)); })
-# endif
+ : __b_strspn (s, accept)))))) \
+ : __b_strspn (s, accept)); })
# endif
__STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept);
--
1.7.4.4