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][RFC] Avoid table lookup in isascii, isxdigit.


On Tue, Apr 09, 2013 at 01:57:06PM +0200, OndÅej BÃlka wrote:
> Hi, I looked to ctype and thougth if it is possible to decrease table
> size to 512 bytes. I did not succeed but made following three
> optimizations.
> 
> 1. In isdigit use & instead &&. Gcc contains bug that optimizes first
> but not second case.
> 2. Refactor isdigit macro
> 3. Write isxdigit and isascii.
> 
> Following code is enclosed in
> 
> #ifndef _ISOMAC
> # if !defined __NO_CTYPE && !defined NOT_IN_libc
> 
> Is there reason why we cannot also transform user code in this way?
> 
> ---
>  include/ctype.h |   23 ++++++++++++++++++++---
>  1 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/include/ctype.h b/include/ctype.h
> index 6a18039..7f9e928 100644
> --- a/include/ctype.h
> +++ b/include/ctype.h
> @@ -56,11 +56,28 @@ __ctype_tolower_loc (void)
>  /* The spec says that isdigit must only match the decimal digits.  We
>     can check this without a memory access.  */
>  #  undef isdigit
> -#  define isdigit(c) ({ int __c = (c); __c >= '0' && __c <= '9'; })
> +#  define isdigit(c) ({ int __c = (c); (__c >= '0') & (__c <= '9'); })

#define isdigit(c) ((unsigned)(c)-'0'<10)

> +#  define isdigit_l(c, l) isdigit(c)

Wrong because it does not evaluate l. For example, if l were
array_of_locales[i++]... You need:

#define isdigit_l(c, l) ((l),isdigit(c))

Rich


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