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

ruby-changes:71760

From: Nobuyoshi <ko1@a...>
Date: Sun, 17 Apr 2022 19:03:01 +0900 (JST)
Subject: [ruby-changes:71760] 2c6876f811 (master): Get rid of magic numbers

https://git.ruby-lang.org/ruby.git/commit/?id=2c6876f811

From 2c6876f811a3c08e69816861127458b967900bcd Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 17 Apr 2022 18:53:29 +0900
Subject: Get rid of magic numbers

---
 ext/objspace/objspace.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index bd80e540cf..04d40627ac 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -629,20 +629,22 @@ count_imemo_objects(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L629
     VALUE hash = setup_hash(argc, argv);
 
     if (imemo_type_ids[0] == 0) {
-        imemo_type_ids[0] = rb_intern("imemo_env");
-	imemo_type_ids[1] = rb_intern("imemo_cref");
-	imemo_type_ids[2] = rb_intern("imemo_svar");
-	imemo_type_ids[3] = rb_intern("imemo_throw_data");
-	imemo_type_ids[4] = rb_intern("imemo_ifunc");
-	imemo_type_ids[5] = rb_intern("imemo_memo");
-	imemo_type_ids[6] = rb_intern("imemo_ment");
-	imemo_type_ids[7] = rb_intern("imemo_iseq");
-	imemo_type_ids[8] = rb_intern("imemo_tmpbuf");
-        imemo_type_ids[9] = rb_intern("imemo_ast");
-        imemo_type_ids[10] = rb_intern("imemo_parser_strterm");
-        imemo_type_ids[11] = rb_intern("imemo_callinfo");
-        imemo_type_ids[12] = rb_intern("imemo_callcache");
-        imemo_type_ids[13] = rb_intern("imemo_constcache");
+#define INIT_IMEMO_TYPE_ID(n) (imemo_type_ids[n] = rb_intern(#n))
+        INIT_IMEMO_TYPE_ID(imemo_env);
+        INIT_IMEMO_TYPE_ID(imemo_cref);
+        INIT_IMEMO_TYPE_ID(imemo_svar);
+        INIT_IMEMO_TYPE_ID(imemo_throw_data);
+        INIT_IMEMO_TYPE_ID(imemo_ifunc);
+        INIT_IMEMO_TYPE_ID(imemo_memo);
+        INIT_IMEMO_TYPE_ID(imemo_ment);
+        INIT_IMEMO_TYPE_ID(imemo_iseq);
+        INIT_IMEMO_TYPE_ID(imemo_tmpbuf);
+        INIT_IMEMO_TYPE_ID(imemo_ast);
+        INIT_IMEMO_TYPE_ID(imemo_parser_strterm);
+        INIT_IMEMO_TYPE_ID(imemo_callinfo);
+        INIT_IMEMO_TYPE_ID(imemo_callcache);
+        INIT_IMEMO_TYPE_ID(imemo_constcache);
+#undef INIT_IMEMO_TYPE_ID
     }
 
     each_object_with_flags(count_imemo_objects_i, (void *)hash);
-- 
cgit v1.2.1


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

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