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:
parent
23ce0a421d
commit
51964bf995
3 changed files with 53 additions and 5 deletions
21
internal.h
21
internal.h
|
@ -1136,7 +1136,26 @@ VALUE rb_sym_to_proc(VALUE sym);
|
|||
|
||||
/* symbol.c */
|
||||
#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
|
||||
|
||||
/* struct.c */
|
||||
|
|
|
@ -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 (nextvalue == Qundef) {
|
||||
if (NIL_P(sym)) {
|
||||
sym = rb_cstr_intern(start + 1,
|
||||
sym = rb_sym_intern(start + 1,
|
||||
len - 2 /* without parenthesis */,
|
||||
enc);
|
||||
}
|
||||
|
|
31
symbol.c
31
symbol.c
|
@ -1014,14 +1014,43 @@ rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
|
|||
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
|
||||
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;
|
||||
const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc);
|
||||
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
|
||||
attrsetname_to_attr_id(VALUE name)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue