ruby-changes:42317
From: naruse <ko1@a...>
Date: Tue, 29 Mar 2016 19:24:12 +0900 (JST)
Subject: [ruby-changes:42317] naruse:r54391 (trunk): * include/ruby/ruby.h (rb_isupper, rb_islower, rb_isalpha, rb_isdigit,
naruse 2016-03-29 19:24:05 +0900 (Tue, 29 Mar 2016) New Revision: 54391 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54391 Log: * include/ruby/ruby.h (rb_isupper, rb_islower, rb_isalpha, rb_isdigit, rb_isalnum, rb_isxdigit, rb_isblank, rb_isspace, rb_isblank, rb_iscntrl, rb_isprint, rb_ispunct, rb_isgraph, rb_tolower, rb_toupper): use inline function to avoid function call. * include/ruby/ruby.h (rb_isascii): use inline function to clarify the logic. Modified files: trunk/ChangeLog trunk/encoding.c trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 54390) +++ include/ruby/ruby.h (revision 54391) @@ -2091,37 +2091,36 @@ int rb_remove_event_hook(rb_event_hook_f https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2091 /* locale insensitive functions */ -#define rb_isascii(c) ((unsigned long)(c) < 128) -int rb_isalnum(int c); -int rb_isalpha(int c); -int rb_isblank(int c); -int rb_iscntrl(int c); -int rb_isdigit(int c); -int rb_isgraph(int c); -int rb_islower(int c); -int rb_isprint(int c); -int rb_ispunct(int c); -int rb_isspace(int c); -int rb_isupper(int c); -int rb_isxdigit(int c); -int rb_tolower(int c); -int rb_toupper(int c); +static inline int rb_isascii(int c){ return '\0' <= c && c <= '\x7f'; } +static inline int rb_isupper(int c){ return 'A' <= c && c <= 'Z'; } +static inline int rb_islower(int c){ return 'a' <= c && c <= 'z'; } +static inline int rb_isalpha(int c){ return rb_isupper(c) || rb_islower(c); } +static inline int rb_isdigit(int c){ return '0' <= c && c <= '9'; } +static inline int rb_isalnum(int c){ return rb_isalpha(c) || rb_isdigit(c); } +static inline int rb_isxdigit(int c){ return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); } +static inline int rb_isblank(int c){ return c == ' ' || c == '\t'; } +static inline int rb_isspace(int c){ return c == ' ' || ('\t' <= c && c <= '\r'); } +static inline int rb_iscntrl(int c){ return ('\0' <= c && c < ' ') || c == '\x7f'; } +static inline int rb_isprint(int c){ return ' ' <= c && c <= '\x7e'; } +static inline int rb_ispunct(int c){ return !rb_isalnum(c); } +static inline int rb_isgraph(int c){ return '!' <= c && c <= '\x7e'; } +static inline int rb_tolower(int c) { return rb_isupper(c) ? (c|0x20) : c; } +static inline int rb_toupper(int c) { return rb_islower(c) ? (c&0x5f) : c; } #ifndef ISPRINT -#define ISASCII(c) rb_isascii((unsigned char)(c)) -#undef ISPRINT -#define ISPRINT(c) rb_isprint((unsigned char)(c)) -#define ISGRAPH(c) rb_isgraph((unsigned char)(c)) -#define ISSPACE(c) rb_isspace((unsigned char)(c)) -#define ISUPPER(c) rb_isupper((unsigned char)(c)) -#define ISLOWER(c) rb_islower((unsigned char)(c)) -#define ISALNUM(c) rb_isalnum((unsigned char)(c)) -#define ISALPHA(c) rb_isalpha((unsigned char)(c)) -#define ISDIGIT(c) rb_isdigit((unsigned char)(c)) -#define ISXDIGIT(c) rb_isxdigit((unsigned char)(c)) +#define ISASCII(c) rb_isascii(c) +#define ISPRINT(c) rb_isprint(c) +#define ISGRAPH(c) rb_isgraph(c) +#define ISSPACE(c) rb_isspace(c) +#define ISUPPER(c) rb_isupper(c) +#define ISLOWER(c) rb_islower(c) +#define ISALNUM(c) rb_isalnum(c) +#define ISALPHA(c) rb_isalpha(c) +#define ISDIGIT(c) rb_isdigit(c) +#define ISXDIGIT(c) rb_isxdigit(c) #endif -#define TOUPPER(c) rb_toupper((unsigned char)(c)) -#define TOLOWER(c) rb_tolower((unsigned char)(c)) +#define TOUPPER(c) rb_toupper(c) +#define TOLOWER(c) rb_tolower(c) int st_locale_insensitive_strcasecmp(const char *s1, const char *s2); int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n); Index: ChangeLog =================================================================== --- ChangeLog (revision 54390) +++ ChangeLog (revision 54391) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Mar 29 19:23:46 2016 NARUSE, Yui <naruse@r...> + + * include/ruby/ruby.h (rb_isupper, rb_islower, rb_isalpha, rb_isdigit, + rb_isalnum, rb_isxdigit, rb_isblank, rb_isspace, rb_isblank, + rb_iscntrl, rb_isprint, rb_ispunct, rb_isgraph, + rb_tolower, rb_toupper): use inline function to avoid function call. + + * include/ruby/ruby.h (rb_isascii): use inline function to clarify + the logic. + Tue Mar 29 18:56:55 2016 NARUSE, Yui <naruse@r...> * tool/redmine-backporter.rb (backport): show merger.rb's path. Index: encoding.c =================================================================== --- encoding.c (revision 54390) +++ encoding.c (revision 54391) @@ -1959,34 +1959,6 @@ Init_Encoding(void) https://github.com/ruby/ruby/blob/trunk/encoding.c#L1959 /* locale insensitive ctype functions */ -#define ctype_test(c, ctype) \ - (rb_isascii(c) && ONIGENC_IS_ASCII_CODE_CTYPE((c), (ctype))) - -int rb_isalnum(int c) { return ctype_test(c, ONIGENC_CTYPE_ALNUM); } -int rb_isalpha(int c) { return ctype_test(c, ONIGENC_CTYPE_ALPHA); } -int rb_isblank(int c) { return ctype_test(c, ONIGENC_CTYPE_BLANK); } -int rb_iscntrl(int c) { return ctype_test(c, ONIGENC_CTYPE_CNTRL); } -int rb_isdigit(int c) { return ctype_test(c, ONIGENC_CTYPE_DIGIT); } -int rb_isgraph(int c) { return ctype_test(c, ONIGENC_CTYPE_GRAPH); } -int rb_islower(int c) { return ctype_test(c, ONIGENC_CTYPE_LOWER); } -int rb_isprint(int c) { return ctype_test(c, ONIGENC_CTYPE_PRINT); } -int rb_ispunct(int c) { return ctype_test(c, ONIGENC_CTYPE_PUNCT); } -int rb_isspace(int c) { return ctype_test(c, ONIGENC_CTYPE_SPACE); } -int rb_isupper(int c) { return ctype_test(c, ONIGENC_CTYPE_UPPER); } -int rb_isxdigit(int c) { return ctype_test(c, ONIGENC_CTYPE_XDIGIT); } - -int -rb_tolower(int c) -{ - return rb_isascii(c) ? ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) : c; -} - -int -rb_toupper(int c) -{ - return rb_isascii(c) ? ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) : c; -} - void rb_enc_foreach_name(int (*func)(st_data_t name, st_data_t idx, st_data_t arg), st_data_t arg) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/