diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-03-11 17:26:19 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-03-11 17:26:19 +0900 |
| commit | 425e6e0ffb0e2935b800866443fb18ccb26a97e4 (patch) | |
| tree | 5322c6be576e379115788220328b931d7440432c /src/class.c | |
| parent | fba8ecf55ceb8bbe07d4beb24ce3c4dea6fde20b (diff) | |
| download | mruby-425e6e0ffb0e2935b800866443fb18ccb26a97e4.tar.gz mruby-425e6e0ffb0e2935b800866443fb18ccb26a97e4.zip | |
Reduce `String` creation in `check_(cv|const)_name_sym`
Diffstat (limited to 'src/class.c')
| -rw-r--r-- | src/class.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/class.c b/src/class.c index bb9515bbd..9d6fd631f 100644 --- a/src/class.c +++ b/src/class.c @@ -1895,18 +1895,20 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod) return mrb_nil_value(); } -static void -check_const_name_str(mrb_state *mrb, mrb_value str) +static mrb_bool +const_name_p(mrb_state *mrb, const char *name, mrb_int len) { - if (RSTRING_LEN(str) < 1 || !ISUPPER(*RSTRING_PTR(str))) { - mrb_name_error(mrb, mrb_intern_str(mrb, str), "wrong constant name %S", str); - } + return len > 0 && ISUPPER(name[0]); } static void check_const_name_sym(mrb_state *mrb, mrb_sym id) { - check_const_name_str(mrb, mrb_sym2str(mrb, id)); + mrb_int len; + const char *name = mrb_sym2name_len(mrb, id, &len); + if (!const_name_p(mrb, name, len)) { + mrb_name_error(mrb, id, "wrong constant name %S", mrb_sym2str(mrb, id)); + } } static mrb_value |
