ruby-changes:65435
From: eileencodes <ko1@a...>
Date: Thu, 11 Mar 2021 02:39:27 +0900 (JST)
Subject: [ruby-changes:65435] 23a48d8fe6 (master): Refactor `rb_class_ivar_set`
https://git.ruby-lang.org/ruby.git/commit/?id=23a48d8fe6 From 23a48d8fe683df289736e2d90c86006eb919b40d Mon Sep 17 00:00:00 2001 From: eileencodes <eileencodes@g...> Date: Wed, 10 Mar 2021 10:24:28 -0500 Subject: Refactor `rb_class_ivar_set` In every caller of `rb_class_ivar_set` it checks for the `RCLASS_IV_TBL` and then creates it if it doesn't exist. Instead of repeating this in every caller, this can be done once in `rb_class_ivar_set`. --- class.c | 3 --- variable.c | 11 ++++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/class.c b/class.c index 68cfbfb..b2e15c2 100644 --- a/class.c +++ b/class.c @@ -529,9 +529,6 @@ void https://github.com/ruby/ruby/blob/trunk/class.c#L529 rb_singleton_class_attached(VALUE klass, VALUE obj) { if (FL_TEST(klass, FL_SINGLETON)) { - if (!RCLASS_IV_TBL(klass)) { - RCLASS_IV_TBL(klass) = st_init_numtable(); - } rb_class_ivar_set(klass, id_attached, obj); } } diff --git a/variable.c b/variable.c index 92d7d11..85ff35b 100644 --- a/variable.c +++ b/variable.c @@ -1480,7 +1480,6 @@ ivar_set(VALUE obj, ID id, VALUE val) https://github.com/ruby/ruby/blob/trunk/variable.c#L1480 case T_CLASS: case T_MODULE: IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(id); - if (!RCLASS_IV_TBL(obj)) RCLASS_IV_TBL(obj) = st_init_numtable(); rb_class_ivar_set(obj, id, val); break; default: @@ -2988,9 +2987,6 @@ set_namespace_path(VALUE named_namespace, VALUE namespace_path) https://github.com/ruby/ruby/blob/trunk/variable.c#L2987 RB_VM_LOCK_ENTER(); { - if (!RCLASS_IV_TBL(named_namespace)) { - RCLASS_IV_TBL(named_namespace) = st_init_numtable(); - } rb_class_ivar_set(named_namespace, classpath, namespace_path); if (const_table) { rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path); @@ -3360,9 +3356,6 @@ rb_cvar_set(VALUE klass, ID id, VALUE val) https://github.com/ruby/ruby/blob/trunk/variable.c#L3356 target = RBASIC(target)->klass; } check_before_mod_set(target, id, val, "class variable"); - if (!RCLASS_IV_TBL(target)) { - RCLASS_IV_TBL(target) = st_init_numtable(); - } rb_class_ivar_set(target, id, val); } @@ -3588,6 +3581,10 @@ rb_iv_set(VALUE obj, const char *name, VALUE val) https://github.com/ruby/ruby/blob/trunk/variable.c#L3581 int rb_class_ivar_set(VALUE obj, ID key, VALUE value) { + if (!RCLASS_IV_TBL(obj)) { + RCLASS_IV_TBL(obj) = st_init_numtable(); + } + st_table *tbl = RCLASS_IV_TBL(obj); int result = st_insert(tbl, (st_data_t)key, (st_data_t)value); RB_OBJ_WRITTEN(obj, Qundef, value); -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/