Commit 425e6e0f authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Reduce `String` creation in `check_(cv|const)_name_sym`

parent fba8ecf5
...@@ -400,21 +400,20 @@ mod_define_singleton_method(mrb_state *mrb, mrb_value self) ...@@ -400,21 +400,20 @@ mod_define_singleton_method(mrb_state *mrb, mrb_value self)
return mrb_symbol_value(mid); return mrb_symbol_value(mid);
} }
static void static mrb_bool
check_cv_name_str(mrb_state *mrb, mrb_value str) cv_name_p(mrb_state *mrb, const char *name, mrb_int len)
{ {
const char *s = RSTRING_PTR(str); return len > 2 && name[0] == '@' && name[1] == '@';
mrb_int len = RSTRING_LEN(str);
if (len < 3 || !(s[0] == '@' && s[1] == '@')) {
mrb_name_error(mrb, mrb_intern_str(mrb, str), "'%S' is not allowed as a class variable name", str);
}
} }
static void static void
check_cv_name_sym(mrb_state *mrb, mrb_sym id) check_cv_name_sym(mrb_state *mrb, mrb_sym id)
{ {
check_cv_name_str(mrb, mrb_sym2str(mrb, id)); mrb_int len;
const char *name = mrb_sym2name_len(mrb, id, &len);
if (!cv_name_p(mrb, name, len)) {
mrb_name_error(mrb, id, "'%S' is not allowed as a class variable name", mrb_sym2str(mrb, id));
}
} }
/* 15.2.2.4.39 */ /* 15.2.2.4.39 */
......
...@@ -1895,18 +1895,20 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod) ...@@ -1895,18 +1895,20 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod)
return mrb_nil_value(); return mrb_nil_value();
} }
static void static mrb_bool
check_const_name_str(mrb_state *mrb, mrb_value str) const_name_p(mrb_state *mrb, const char *name, mrb_int len)
{ {
if (RSTRING_LEN(str) < 1 || !ISUPPER(*RSTRING_PTR(str))) { return len > 0 && ISUPPER(name[0]);
mrb_name_error(mrb, mrb_intern_str(mrb, str), "wrong constant name %S", str);
}
} }
static void static void
check_const_name_sym(mrb_state *mrb, mrb_sym id) 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 static mrb_value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment