From 51964bf995b7f3b0c1202646fc619b91e052f648 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 30 Nov 2015 04:44:39 +0000 Subject: [PATCH] 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 --- internal.h | 21 ++++++++++++++++++++- sprintf.c | 6 +++--- symbol.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/internal.h b/internal.h index 82de64fa60..d3db0a6104 100644 --- a/internal.h +++ b/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 */ diff --git a/sprintf.c b/sprintf.c index c2e5de5d64..99c97a01c0 100644 --- a/sprintf.c +++ b/sprintf.c @@ -611,9 +611,9 @@ 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, - len - 2 /* without parenthesis */, - enc); + sym = rb_sym_intern(start + 1, + len - 2 /* without parenthesis */, + enc); } nextvalue = rb_hash_default_value(hash, sym); if (NIL_P(nextvalue)) { diff --git a/symbol.c b/symbol.c index 65ffab0958..8e3e0c3c55 100644 --- a/symbol.c +++ b/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) {