[前][次][番号順一覧][スレッド一覧]

ruby-changes:40713

From: nobu <ko1@a...>
Date: Mon, 30 Nov 2015 13:44:54 +0900 (JST)
Subject: [ruby-changes:40713] nobu:r52792 (trunk): symbol.c: rb_sym_intern

nobu	2015-11-30 13:44:39 +0900 (Mon, 30 Nov 2015)

  New Revision: 52792

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52792

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

  Modified files:
    trunk/internal.h
    trunk/sprintf.c
    trunk/symbol.c
Index: symbol.c
===================================================================
--- symbol.c	(revision 52791)
+++ symbol.c	(revision 52792)
@@ -1014,14 +1014,43 @@ rb_check_symbol_cstr(const char *ptr, lo https://github.com/ruby/ruby/blob/trunk/symbol.c#L1014
     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)
 {
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 52791)
+++ sprintf.c	(revision 52792)
@@ -611,9 +611,9 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L611
 		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)) {
Index: internal.h
===================================================================
--- internal.h	(revision 52791)
+++ internal.h	(revision 52792)
@@ -1136,7 +1136,26 @@ VALUE rb_sym_to_proc(VALUE sym); https://github.com/ruby/ruby/blob/trunk/internal.h#L1136
 
 /* 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 */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]