1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

symbol.c: rb_sym_intern

* symbol.c (rb_sym_intern): rename from rb_cstr_intern and add
  variants.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-11-30 04:44:39 +00:00
parent 23ce0a421d
commit 51964bf995
3 changed files with 53 additions and 5 deletions

View file

@ -1136,7 +1136,26 @@ VALUE rb_sym_to_proc(VALUE sym);
/* symbol.c */ /* symbol.c */
#ifdef RUBY_ENCODING_H #ifdef RUBY_ENCODING_H
VALUE rb_cstr_intern(const char *ptr, long len, rb_encoding *enc); VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
VALUE rb_sym_intern_cstr(const char *ptr, rb_encoding *enc);
#ifdef __GNUC__
#define rb_sym_intern_cstr(ptr, enc) __extension__ ( \
{ \
(__builtin_constant_p(ptr)) ? \
rb_sym_intern((ptr), (long)strlen(ptr), (enc)) : \
rb_sym_intern_cstr((ptr), (enc)); \
})
#endif
#endif
VALUE rb_sym_intern_ascii(const char *ptr, long len);
VALUE rb_sym_intern_ascii_cstr(const char *ptr);
#ifdef __GNUC__
#define rb_sym_intern_ascii_cstr(ptr) __extension__ ( \
{ \
(__builtin_constant_p(ptr)) ? \
rb_sym_intern_ascii((ptr), (long)strlen(ptr)) : \
rb_sym_intern_ascii_cstr(ptr); \
})
#endif #endif
/* struct.c */ /* struct.c */

View file

@ -611,7 +611,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (!NIL_P(sym)) nextvalue = rb_hash_lookup2(hash, sym, Qundef); if (!NIL_P(sym)) nextvalue = rb_hash_lookup2(hash, sym, Qundef);
if (nextvalue == Qundef) { if (nextvalue == Qundef) {
if (NIL_P(sym)) { if (NIL_P(sym)) {
sym = rb_cstr_intern(start + 1, sym = rb_sym_intern(start + 1,
len - 2 /* without parenthesis */, len - 2 /* without parenthesis */,
enc); enc);
} }

View file

@ -1014,14 +1014,43 @@ rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
return Qnil; return Qnil;
} }
#undef rb_sym_intern_cstr
#undef rb_sym_intern_ascii_cstr
#ifdef __clang__
NOINLINE(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc));
#else
FUNC_MINIMIZED(VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc));
FUNC_MINIMIZED(VALUE rb_sym_intern_cstr(const char *ptr, rb_encoding *enc));
FUNC_MINIMIZED(VALUE rb_sym_intern_ascii(const char *ptr, long len));
FUNC_MINIMIZED(VALUE rb_sym_intern_ascii_cstr(const char *ptr));
#endif
VALUE VALUE
rb_cstr_intern(const char *ptr, long len, rb_encoding *enc) rb_sym_intern(const char *ptr, long len, rb_encoding *enc)
{ {
struct RString fake_str; struct RString fake_str;
const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc); const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
return rb_str_intern(name); return rb_str_intern(name);
} }
VALUE
rb_sym_intern_cstr(const char *ptr, rb_encoding *enc)
{
return rb_sym_intern(ptr, strlen(ptr), enc);
}
VALUE
rb_sym_intern_ascii(const char *ptr, long len)
{
return rb_sym_intern(ptr, len, rb_usascii_encoding());
}
VALUE
rb_sym_intern_ascii_cstr(const char *ptr)
{
return rb_sym_intern_ascii(ptr, strlen(ptr));
}
static ID static ID
attrsetname_to_attr_id(VALUE name) attrsetname_to_attr_id(VALUE name)
{ {