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

ruby-changes:66902

From: Nobuyoshi <ko1@a...>
Date: Tue, 27 Jul 2021 15:40:49 +0900 (JST)
Subject: [ruby-changes:66902] 03e7fc895e (master): Extracted repeatedly defined IDs

https://git.ruby-lang.org/ruby.git/commit/?id=03e7fc895e

From 03e7fc895e9dbe420cad192f1ba679df558640dd Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 27 Jul 2021 09:27:29 +0900
Subject: Extracted repeatedly defined IDs

---
 enum.c      | 80 ++++++++++++++++++++++++++++++++++++++++---------------------
 transcode.c | 50 +++++++++++++++++++++++++-------------
 2 files changed, 87 insertions(+), 43 deletions(-)

diff --git a/enum.c b/enum.c
index 0538f43..c576ba7 100644
--- a/enum.c
+++ b/enum.c
@@ -27,6 +27,19 @@ https://github.com/ruby/ruby/blob/trunk/enum.c#L27
 VALUE rb_mEnumerable;
 
 static ID id_next;
+static ID id__alone;
+static ID id__separator;
+static ID id_chunk_categorize;
+static ID id_chunk_enumerable;
+static ID id_sliceafter_enum;
+static ID id_sliceafter_pat;
+static ID id_sliceafter_pred;
+static ID id_slicebefore_enumerable;
+static ID id_slicebefore_sep_pat;
+static ID id_slicebefore_sep_pred;
+static ID id_slicewhen_enum;
+static ID id_slicewhen_inverted;
+static ID id_slicewhen_pred;
 
 #define id_div idDiv
 #define id_each idEach
@@ -3188,8 +3201,8 @@ chunk_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, _argp)) https://github.com/ruby/ruby/blob/trunk/enum.c#L3201
 {
     struct chunk_arg *argp = MEMO_FOR(struct chunk_arg, _argp);
     VALUE v, s;
-    VALUE alone = ID2SYM(rb_intern("_alone"));
-    VALUE separator = ID2SYM(rb_intern("_separator"));
+    VALUE alone = ID2SYM(id__alone);
+    VALUE separator = ID2SYM(id__separator);
 
     ENUM_WANT_SVALUE();
 
@@ -3241,8 +3254,8 @@ chunk_i(RB_BLOCK_CALL_FUNC_ARGLIST(yielder, enumerator)) https://github.com/ruby/ruby/blob/trunk/enum.c#L3254
     VALUE arg;
     struct chunk_arg *memo = NEW_MEMO_FOR(struct chunk_arg, arg);
 
-    enumerable = rb_ivar_get(enumerator, rb_intern("chunk_enumerable"));
-    memo->categorize = rb_ivar_get(enumerator, rb_intern("chunk_categorize"));
+    enumerable = rb_ivar_get(enumerator, id_chunk_enumerable);
+    memo->categorize = rb_ivar_get(enumerator, id_chunk_categorize);
     memo->prev_value = Qnil;
     memo->prev_elts = Qnil;
     memo->yielder = yielder;
@@ -3352,8 +3365,8 @@ enum_chunk(VALUE enumerable) https://github.com/ruby/ruby/blob/trunk/enum.c#L3365
     RETURN_SIZED_ENUMERATOR(enumerable, 0, 0, enum_size);
 
     enumerator = rb_obj_alloc(rb_cEnumerator);
-    rb_ivar_set(enumerator, rb_intern("chunk_enumerable"), enumerable);
-    rb_ivar_set(enumerator, rb_intern("chunk_categorize"), rb_block_proc());
+    rb_ivar_set(enumerator, id_chunk_enumerable, enumerable);
+    rb_ivar_set(enumerator, id_chunk_categorize, rb_block_proc());
     rb_block_call(enumerator, idInitialize, 0, 0, chunk_i, enumerator);
     return enumerator;
 }
@@ -3400,9 +3413,9 @@ slicebefore_i(RB_BLOCK_CALL_FUNC_ARGLIST(yielder, enumerator)) https://github.com/ruby/ruby/blob/trunk/enum.c#L3413
     VALUE arg;
     struct slicebefore_arg *memo = NEW_MEMO_FOR(struct slicebefore_arg, arg);
 
-    enumerable = rb_ivar_get(enumerator, rb_intern("slicebefore_enumerable"));
-    memo->sep_pred = rb_attr_get(enumerator, rb_intern("slicebefore_sep_pred"));
-    memo->sep_pat = NIL_P(memo->sep_pred) ? rb_ivar_get(enumerator, rb_intern("slicebefore_sep_pat")) : Qnil;
+    enumerable = rb_ivar_get(enumerator, id_slicebefore_enumerable);
+    memo->sep_pred = rb_attr_get(enumerator, id_slicebefore_sep_pred);
+    memo->sep_pat = NIL_P(memo->sep_pred) ? rb_ivar_get(enumerator, id_slicebefore_sep_pat) : Qnil;
     memo->prev_elts = Qnil;
     memo->yielder = yielder;
 
@@ -3566,15 +3579,15 @@ enum_slice_before(int argc, VALUE *argv, VALUE enumerable) https://github.com/ruby/ruby/blob/trunk/enum.c#L3579
         if (argc != 0)
             rb_error_arity(argc, 0, 0);
         enumerator = rb_obj_alloc(rb_cEnumerator);
-        rb_ivar_set(enumerator, rb_intern("slicebefore_sep_pred"), rb_block_proc());
+        rb_ivar_set(enumerator, id_slicebefore_sep_pred, rb_block_proc());
     }
     else {
         VALUE sep_pat;
         rb_scan_args(argc, argv, "1", &sep_pat);
         enumerator = rb_obj_alloc(rb_cEnumerator);
-        rb_ivar_set(enumerator, rb_intern("slicebefore_sep_pat"), sep_pat);
+        rb_ivar_set(enumerator, id_slicebefore_sep_pat, sep_pat);
     }
-    rb_ivar_set(enumerator, rb_intern("slicebefore_enumerable"), enumerable);
+    rb_ivar_set(enumerator, id_slicebefore_enumerable, enumerable);
     rb_block_call(enumerator, idInitialize, 0, 0, slicebefore_i, enumerator);
     return enumerator;
 }
@@ -3630,9 +3643,9 @@ sliceafter_i(RB_BLOCK_CALL_FUNC_ARGLIST(yielder, enumerator)) https://github.com/ruby/ruby/blob/trunk/enum.c#L3643
     VALUE arg;
     struct sliceafter_arg *memo = NEW_MEMO_FOR(struct sliceafter_arg, arg);
 
-    enumerable = rb_ivar_get(enumerator, rb_intern("sliceafter_enum"));
-    memo->pat = rb_ivar_get(enumerator, rb_intern("sliceafter_pat"));
-    memo->pred = rb_attr_get(enumerator, rb_intern("sliceafter_pred"));
+    enumerable = rb_ivar_get(enumerator, id_sliceafter_enum);
+    memo->pat = rb_ivar_get(enumerator, id_sliceafter_pat);
+    memo->pred = rb_attr_get(enumerator, id_sliceafter_pred);
     memo->prev_elts = Qnil;
     memo->yielder = yielder;
 
@@ -3695,9 +3708,9 @@ enum_slice_after(int argc, VALUE *argv, VALUE enumerable) https://github.com/ruby/ruby/blob/trunk/enum.c#L3708
     }
 
     enumerator = rb_obj_alloc(rb_cEnumerator);
-    rb_ivar_set(enumerator, rb_intern("sliceafter_enum"), enumerable);
-    rb_ivar_set(enumerator, rb_intern("sliceafter_pat"), pat);
-    rb_ivar_set(enumerator, rb_intern("sliceafter_pred"), pred);
+    rb_ivar_set(enumerator, id_sliceafter_enum, enumerable);
+    rb_ivar_set(enumerator, id_sliceafter_pat, pat);
+    rb_ivar_set(enumerator, id_sliceafter_pred, pred);
 
     rb_block_call(enumerator, idInitialize, 0, 0, sliceafter_i, enumerator);
     return enumerator;
@@ -3760,12 +3773,12 @@ slicewhen_i(RB_BLOCK_CALL_FUNC_ARGLIST(yielder, enumerator)) https://github.com/ruby/ruby/blob/trunk/enum.c#L3773
     struct slicewhen_arg *memo =
 	NEW_PARTIAL_MEMO_FOR(struct slicewhen_arg, arg, inverted);
 
-    enumerable = rb_ivar_get(enumerator, rb_intern("slicewhen_enum"));
-    memo->pred = rb_attr_get(enumerator, rb_intern("slicewhen_pred"));
+    enumerable = rb_ivar_get(enumerator, id_slicewhen_enum);
+    memo->pred = rb_attr_get(enumerator, id_slicewhen_pred);
     memo->prev_elt = Qundef;
     memo->prev_elts = Qnil;
     memo->yielder = yielder;
-    memo->inverted = RTEST(rb_attr_get(enumerator, rb_intern("slicewhen_inverted")));
+    memo->inverted = RTEST(rb_attr_get(enumerator, id_slicewhen_inverted));
 
     rb_block_call(enumerable, id_each, 0, 0, slicewhen_ii, arg);
     memo = MEMO_FOR(struct slicewhen_arg, arg);
@@ -3845,9 +3858,9 @@ enum_slice_when(VALUE enumerable) https://github.com/ruby/ruby/blob/trunk/enum.c#L3858
     pred = rb_block_proc();
 
     enumerator = rb_obj_alloc(rb_cEnumerator);
-    rb_ivar_set(enumerator, rb_intern("slicewhen_enum"), enumerable);
-    rb_ivar_set(enumerator, rb_intern("slicewhen_pred"), pred);
-    rb_ivar_set(enumerator, rb_intern("slicewhen_inverted"), Qfalse);
+    rb_ivar_set(enumerator, id_slicewhen_enum, enumerable);
+    rb_ivar_set(enumerator, id_slicewhen_pred, pred);
+    rb_ivar_set(enumerator, id_slicewhen_inverted, Qfalse);
 
     rb_block_call(enumerator, idInitialize, 0, 0, slicewhen_i, enumerator);
     return enumerator;
@@ -3911,9 +3924,9 @@ enum_chunk_while(VALUE enumerable) https://github.com/ruby/ruby/blob/trunk/enum.c#L3924
     pred = rb_block_proc();
 
     enumerator = rb_obj_alloc(rb_cEnumerator);
-    rb_ivar_set(enumerator, rb_intern("slicewhen_enum"), enumerable);
-    rb_ivar_set(enumerator, rb_intern("slicewhen_pred"), pred);
-    rb_ivar_set(enumerator, rb_intern("slicewhen_inverted"), Qtrue);
+    rb_ivar_set(enumerator, id_slicewhen_enum, enumerable);
+    rb_ivar_set(enumerator, id_slicewhen_pred, pred);
+    rb_ivar_set(enumerator, id_slicewhen_inverted, Qtrue);
 
     rb_block_call(enumerator, idInitialize, 0, 0, slicewhen_i, enumerator);
     return enumerator;
@@ -4469,5 +4482,18 @@ Init_Enumerable(void) https://github.com/ruby/ruby/blob/trunk/enum.c#L4482
     rb_define_method(rb_mEnumerable, "uniq", enum_uniq, 0);
     rb_define_method(rb_mEnumerable, "compact", enum_compact, 0);
 
+    id__alone = rb_intern_const("_alone");
+    id__separator = rb_intern_const("_separator");
+    id_chunk_categorize = rb_intern_const("chunk_categorize");
+    id_chunk_enumerable = rb_intern_const("chunk_enumerable");
     id_next = rb_intern_const("next");
+    id_sliceafter_enum = rb_intern_const("sliceafter_enum");
+    id_sliceafter_pat = rb_intern_const("sliceafter_pat");
+    id_sliceafter_pred = rb_intern_const("sliceafter_pred");
+    id_slicebefore_enumerable = rb_intern_const("slicebefore_enumerable");
+    id_slicebefore_sep_pat = rb_intern_const("slicebefore_sep_pat");
+    id_slicebefore_sep_pred = rb_intern_const("slicebefore_sep_pred");
+    id_slicewhen_enum = rb_intern_const("slicewhen_enum");
+    id_slicewhen_inverted = rb_intern_const("slicewhen_inverted");
+    id_slicewhen_pred = rb_intern_const("slicewhen_pred");
 }
diff --git a/transcode.c b/transcode.c
index a865cb4..e4ff326 100644
--- a/transcode.c
+++ b/transcode.c
@@ -33,6 +33,15 @@ static VALUE rb_eConverterNotFoundError; https://github.com/ruby/ruby/blob/trunk/transcode.c#L33
 
 VALUE rb_cEncodingConverter;
 
+static ID id_destination_encoding;
+static ID id_destination_encoding_name;
+static ID id_error_bytes;
+static ID id_error_char;
+static ID id_incomplete_input;
+static ID id_readagain_bytes;
+static ID id_source_encoding;
+static ID id_source_encoding_name;
+
 static VALUE sym_invalid, sym_undef, sym_replace, sym_fallback;
 static VALUE sym_xml, sym_text, sym_attr;
 static VALUE sym_universal_newline;
@@ -2068,9 +2077,9 @@ make_econv_exception(rb_econv_t *ec) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2077
         }
 
         exc = rb_exc_new3(rb_eInvalidByteSequenceError, mesg);
-        rb_ivar_set(exc, rb_intern(" (... truncated)

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

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