aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--encoding.c28
-rw-r--r--include/ruby/ruby.h57
3 files changed, 38 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index c7665cfcfd..7183c12bd3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue Mar 29 19:23:46 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* tool/redmine-backporter.rb (backport): show merger.rb's path.
diff --git a/encoding.c b/encoding.c
index ed710a9dfb..948b1781ac 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1959,34 +1959,6 @@ Init_Encoding(void)
/* 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)
{
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 5cc8718132..c41465adef 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -2091,37 +2091,36 @@ int rb_remove_event_hook(rb_event_hook_func_t func);
/* 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))
-#endif
-#define TOUPPER(c) rb_toupper((unsigned char)(c))
-#define TOLOWER(c) rb_tolower((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(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);