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

ruby-changes:63402

From: Stefan <ko1@a...>
Date: Wed, 21 Oct 2020 12:54:34 +0900 (JST)
Subject: [ruby-changes:63402] 8c2e5bbf58 (master): Don't redefine #rb_intern over and over again

https://git.ruby-lang.org/ruby.git/commit/?id=8c2e5bbf58

From 8c2e5bbf58e562ea410b53c2f77e4186d5ca9da3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Stu=CC=88ben?= <MSNexploder@g...>
Date: Fri, 25 Sep 2020 19:56:30 +0200
Subject: Don't redefine #rb_intern over and over again


diff --git a/array.c b/array.c
index 9183dfc..6cd6412 100644
--- a/array.c
+++ b/array.c
@@ -8018,9 +8018,6 @@ rb_ary_deconstruct(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L8018
 void
 Init_Array(void)
 {
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
-
     rb_cArray  = rb_define_class("Array", rb_cObject);
     rb_include_module(rb_cArray, rb_mEnumerable);
 
diff --git a/compar.c b/compar.c
index 6e64e3d..04d4ff8 100644
--- a/compar.c
+++ b/compar.c
@@ -294,9 +294,6 @@ cmp_clamp(int argc, VALUE *argv, VALUE x) https://github.com/ruby/ruby/blob/trunk/compar.c#L294
 void
 Init_Comparable(void)
 {
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
-
     rb_mComparable = rb_define_module("Comparable");
     rb_define_method(rb_mComparable, "==", cmp_equal, 1);
     rb_define_method(rb_mComparable, ">", cmp_gt, 1);
diff --git a/compile.c b/compile.c
index ff63dfe..5086e33 100644
--- a/compile.c
+++ b/compile.c
@@ -9134,18 +9134,16 @@ register_label(rb_iseq_t *iseq, struct st_table *labels_table, VALUE obj) https://github.com/ruby/ruby/blob/trunk/compile.c#L9134
 static VALUE
 get_exception_sym2type(VALUE sym)
 {
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
     static VALUE symRescue, symEnsure, symRetry;
     static VALUE symBreak, symRedo, symNext;
 
     if (symRescue == 0) {
-	symRescue = ID2SYM(rb_intern("rescue"));
-	symEnsure = ID2SYM(rb_intern("ensure"));
-	symRetry  = ID2SYM(rb_intern("retry"));
-	symBreak  = ID2SYM(rb_intern("break"));
-	symRedo   = ID2SYM(rb_intern("redo"));
-	symNext   = ID2SYM(rb_intern("next"));
+	symRescue = ID2SYM(rb_intern_const("rescue"));
+	symEnsure = ID2SYM(rb_intern_const("ensure"));
+	symRetry  = ID2SYM(rb_intern_const("retry"));
+	symBreak  = ID2SYM(rb_intern_const("break"));
+	symRedo   = ID2SYM(rb_intern_const("redo"));
+	symNext   = ID2SYM(rb_intern_const("next"));
     }
 
     if (sym == symRescue) return CATCH_TYPE_RESCUE;
@@ -9211,7 +9209,7 @@ insn_make_insn_table(void) https://github.com/ruby/ruby/blob/trunk/compile.c#L9209
     table = st_init_numtable_with_size(VM_INSTRUCTION_SIZE);
 
     for (i=0; i<VM_INSTRUCTION_SIZE; i++) {
-	st_insert(table, ID2SYM(rb_intern(insn_name(i))), i);
+	st_insert(table, ID2SYM(rb_intern_const(insn_name(i))), i);
     }
 
     return table;
@@ -9246,10 +9244,10 @@ iseq_build_callinfo_from_hash(rb_iseq_t *iseq, VALUE op) https://github.com/ruby/ruby/blob/trunk/compile.c#L9244
     struct rb_callinfo_kwarg *kw_arg = 0;
 
     if (!NIL_P(op)) {
-	VALUE vmid = rb_hash_aref(op, ID2SYM(rb_intern("mid")));
-	VALUE vflag = rb_hash_aref(op, ID2SYM(rb_intern("flag")));
-	VALUE vorig_argc = rb_hash_aref(op, ID2SYM(rb_intern("orig_argc")));
-	VALUE vkw_arg = rb_hash_aref(op, ID2SYM(rb_intern("kw_arg")));
+	VALUE vmid = rb_hash_aref(op, ID2SYM(rb_intern_const("mid")));
+	VALUE vflag = rb_hash_aref(op, ID2SYM(rb_intern_const("flag")));
+	VALUE vorig_argc = rb_hash_aref(op, ID2SYM(rb_intern_const("orig_argc")));
+	VALUE vkw_arg = rb_hash_aref(op, ID2SYM(rb_intern_const("kw_arg")));
 
 	if (!NIL_P(vmid)) mid = SYM2ID(vmid);
 	if (!NIL_P(vflag)) flag = NUM2UINT(vflag);
@@ -9278,7 +9276,7 @@ iseq_build_callinfo_from_hash(rb_iseq_t *iseq, VALUE op) https://github.com/ruby/ruby/blob/trunk/compile.c#L9276
 static rb_event_flag_t
 event_name_to_flag(VALUE sym)
 {
-#define CHECK_EVENT(ev) if (sym == ID2SYM(rb_intern(#ev))) return ev;
+#define CHECK_EVENT(ev) if (sym == ID2SYM(rb_intern_const(#ev))) return ev;
 		CHECK_EVENT(RUBY_EVENT_LINE);
 		CHECK_EVENT(RUBY_EVENT_CLASS);
 		CHECK_EVENT(RUBY_EVENT_END);
@@ -9483,7 +9481,7 @@ iseq_build_kw(rb_iseq_t *iseq, VALUE params, VALUE keywords) https://github.com/ruby/ruby/blob/trunk/compile.c#L9481
     iseq->body->param.flags.has_kw = TRUE;
 
     keyword->num = len;
-#define SYM(s) ID2SYM(rb_intern(#s))
+#define SYM(s) ID2SYM(rb_intern_const(#s))
     (void)int_param(&keyword->bits_start, params, SYM(kwbits));
     i = keyword->bits_start - keyword->num;
     ids = (ID *)&iseq->body->local_table[i];
@@ -9596,7 +9594,7 @@ void https://github.com/ruby/ruby/blob/trunk/compile.c#L9594
 rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params,
 			 VALUE exception, VALUE body)
 {
-#define SYM(s) ID2SYM(rb_intern(#s))
+#define SYM(s) ID2SYM(rb_intern_const(#s))
     int i, len;
     unsigned int arg_size, local_size, stack_max;
     ID *tbl;
@@ -9604,7 +9602,7 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, VALUE locals, VALUE params, https://github.com/ruby/ruby/blob/trunk/compile.c#L9602
     VALUE labels_wrapper = Data_Wrap_Struct(0, rb_mark_set, st_free_table, labels_table);
     VALUE arg_opt_labels = rb_hash_aref(params, SYM(opt));
     VALUE keywords = rb_hash_aref(params, SYM(keyword));
-    VALUE sym_arg_rest = ID2SYM(rb_intern("#arg_rest"));
+    VALUE sym_arg_rest = ID2SYM(rb_intern_const("#arg_rest"));
     DECL_ANCHOR(anchor);
     INIT_ANCHOR(anchor);
 
diff --git a/complex.c b/complex.c
index 4100fac..377aae5 100644
--- a/complex.c
+++ b/complex.c
@@ -2337,20 +2337,17 @@ void https://github.com/ruby/ruby/blob/trunk/complex.c#L2337
 Init_Complex(void)
 {
     VALUE compat;
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
-
-    id_abs = rb_intern("abs");
-    id_arg = rb_intern("arg");
-    id_denominator = rb_intern("denominator");
-    id_numerator = rb_intern("numerator");
-    id_real_p = rb_intern("real?");
-    id_i_real = rb_intern("@real");
-    id_i_imag = rb_intern("@image"); /* @image, not @imag */
-    id_finite_p = rb_intern("finite?");
-    id_infinite_p = rb_intern("infinite?");
-    id_rationalize = rb_intern("rationalize");
-    id_PI = rb_intern("PI");
+    id_abs = rb_intern_const("abs");
+    id_arg = rb_intern_const("arg");
+    id_denominator = rb_intern_const("denominator");
+    id_numerator = rb_intern_const("numerator");
+    id_real_p = rb_intern_const("real?");
+    id_i_real = rb_intern_const("@real");
+    id_i_imag = rb_intern_const("@image"); /* @image, not @imag */
+    id_finite_p = rb_intern_const("finite?");
+    id_infinite_p = rb_intern_const("infinite?");
+    id_rationalize = rb_intern_const("rationalize");
+    id_PI = rb_intern_const("PI");
 
     rb_cComplex = rb_define_class("Complex", rb_cNumeric);
 
diff --git a/encoding.c b/encoding.c
index 7f798cd..7336421 100644
--- a/encoding.c
+++ b/encoding.c
@@ -2145,8 +2145,6 @@ rb_enc_aliases(VALUE klass) https://github.com/ruby/ruby/blob/trunk/encoding.c#L2145
 void
 Init_Encoding(void)
 {
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
     VALUE list;
     int i;
 
diff --git a/enum.c b/enum.c
index 69c1641..88d6730 100644
--- a/enum.c
+++ b/enum.c
@@ -4172,9 +4172,6 @@ enum_uniq(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enum.c#L4172
 void
 Init_Enumerable(void)
 {
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
-
     rb_mEnumerable = rb_define_module("Enumerable");
 
     rb_define_method(rb_mEnumerable, "to_a", enum_to_a, -1);
@@ -4236,5 +4233,5 @@ Init_Enumerable(void) https://github.com/ruby/ruby/blob/trunk/enum.c#L4233
     rb_define_method(rb_mEnumerable, "sum", enum_sum, -1);
     rb_define_method(rb_mEnumerable, "uniq", enum_uniq, 0);
 
-    id_next = rb_intern("next");
+    id_next = rb_intern_const("next");
 }
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index f9567e2..bb0482c 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -9116,13 +9116,10 @@ d_lite_zero(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L9116
 void
 Init_date_core(void)
 {
-#undef rb_intern
-#define rb_intern(str) rb_intern_const(str)
-
-    id_cmp = rb_intern("<=>");
-    id_le_p = rb_intern("<=");
-    id_ge_p = rb_intern(">=");
-    id_eqeq_p = rb_intern("==");
+    id_cmp = rb_intern_const("<=>");
+    id_le_p = rb_intern_const("<=");
+    id_ge_p = rb_intern_const(">=");
+    id_eqeq_p = rb_intern_const("==");
 
     half_days_in_day = rb_rational_new2(INT2FIX(1), INT2FIX(2));
 
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index fe2e85b..4b7efa3 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -2456,8 +2456,6 @@ ossl_ssl_tmp_key(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L2456
 # endif /* defined(HAVE_SSL_GET_SERVER_TMP_KEY) */
 #endif /* !defined(OPENSSL_NO_SOCK) */
 
-#undef rb_intern
-#define rb_intern(s) rb_intern_const(s)
 void
 Init_ossl_ssl(void)
 {
@@ -2468,8 +2466,8 @@ Init_ossl_ssl(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L2466
     rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
 #endif
 
-    id_call = rb_intern("call");
-    ID_callback_state = rb_intern("callback_state");
+    id_call = rb_intern_const("call");
+    ID_callback_state = rb_intern_const("callback_state");
 
     ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0, (void *)"ossl_ssl_ex_vcb_idx", 0, 0, 0);
     if (ossl_ssl_ex_vcb_idx < 0)
@@ -2536,7 +2534,7 @@ Init_ossl_ssl(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L2534
      * The _cert_, _key_, and _extra_chain_cert_ attributes are deprecated.
      * It is recommended to use #add_certificate instead.
      */
-    rb_attr(cSSLContext, rb_intern("cert"), 1, 1, Qfalse);
+    rb_attr(cSSLContext, rb_intern_const("cert"), 1, 1, Qfalse);
 
     /*
      * Context private key
@@ -2544,29 +2542,29 @@ Init_ossl_ssl(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L2542
      * The _cert_, _key_, and _extra_chain_cert_ attributes are deprecated.
      * It is recommended to use #add_certificate instead.
      */
-    rb_attr(cSSLContext, rb_intern("key"), 1, 1, Qfalse);
+    rb_attr(cSSLContext, rb_intern_const("key"), 1, 1, Qfalse);
  (... truncated)

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

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