ruby-changes:65109
From: Matt <ko1@a...>
Date: Tue, 2 Feb 2021 01:43:19 +0900 (JST)
Subject: [ruby-changes:65109] e0f999a2ed (master): Add RCLASS_SUBCLASSES Macro
https://git.ruby-lang.org/ruby.git/commit/?id=e0f999a2ed From e0f999a2ed8b1b9298e51d5dfa902044709ce00a Mon Sep 17 00:00:00 2001 From: Matt Valentine-House <matt@e...> Date: Tue, 26 Jan 2021 16:49:57 +0000 Subject: Add RCLASS_SUBCLASSES Macro --- class.c | 20 ++++++++++---------- gc.c | 8 ++++---- internal/class.h | 1 + vm_method.c | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/class.c b/class.c index 2a18eab..f97956c 100644 --- a/class.c +++ b/class.c @@ -53,14 +53,14 @@ rb_class_subclass_add(VALUE super, VALUE klass) https://github.com/ruby/ruby/blob/trunk/class.c#L53 entry->klass = klass; entry->next = NULL; - head = RCLASS_EXT(super)->subclasses; + head = RCLASS_SUBCLASSES(super); if (head) { entry->next = head; RCLASS_PARENT_SUBCLASSES(head->klass) = &entry->next; } - RCLASS_EXT(super)->subclasses = entry; - RCLASS_PARENT_SUBCLASSES(klass) = &RCLASS_EXT(super)->subclasses; + RCLASS_SUBCLASSES(super) = entry; + RCLASS_PARENT_SUBCLASSES(klass) = &RCLASS_SUBCLASSES(super); } } @@ -73,14 +73,14 @@ rb_module_add_to_subclasses_list(VALUE module, VALUE iclass) https://github.com/ruby/ruby/blob/trunk/class.c#L73 entry->klass = iclass; entry->next = NULL; - head = RCLASS_EXT(module)->subclasses; + head = RCLASS_SUBCLASSES(module); if (head) { entry->next = head; RCLASS_MODULE_SUBCLASSES(head->klass) = &entry->next; } - RCLASS_EXT(module)->subclasses = entry; - RCLASS_MODULE_SUBCLASSES(iclass) = &RCLASS_EXT(module)->subclasses; + RCLASS_SUBCLASSES(module) = entry; + RCLASS_MODULE_SUBCLASSES(iclass) = &RCLASS_SUBCLASSES(module); } void @@ -123,7 +123,7 @@ rb_class_remove_from_module_subclasses(VALUE klass) https://github.com/ruby/ruby/blob/trunk/class.c#L123 void rb_class_foreach_subclass(VALUE klass, void (*f)(VALUE, VALUE), VALUE arg) { - rb_subclass_entry_t *cur = RCLASS_EXT(klass)->subclasses; + rb_subclass_entry_t *cur = RCLASS_SUBCLASSES(klass); /* do not be tempted to simplify this loop into a for loop, the order of operations is important here if `f` modifies the linked list */ @@ -181,7 +181,7 @@ class_alloc(VALUE flags, VALUE klass) https://github.com/ruby/ruby/blob/trunk/class.c#L181 RCLASS_M_TBL(obj) = 0; RCLASS_IV_INDEX_TBL(obj) = 0; RCLASS_SET_SUPER((VALUE)obj, 0); - RCLASS_EXT(obj)->subclasses = NULL; + RCLASS_SUBCLASSES(obj) = NULL; RCLASS_PARENT_SUBCLASSES(obj) = NULL; RCLASS_MODULE_SUBCLASSES(obj) = NULL; */ @@ -979,7 +979,7 @@ rb_include_module(VALUE klass, VALUE module) https://github.com/ruby/ruby/blob/trunk/class.c#L979 rb_raise(rb_eArgError, "cyclic include detected"); if (RB_TYPE_P(klass, T_MODULE)) { - rb_subclass_entry_t *iclass = RCLASS_EXT(klass)->subclasses; + rb_subclass_entry_t *iclass = RCLASS_SUBCLASSES(klass); int do_include = 1; while (iclass) { VALUE check_class = iclass->klass; @@ -1190,7 +1190,7 @@ rb_prepend_module(VALUE klass, VALUE module) https://github.com/ruby/ruby/blob/trunk/class.c#L1190 rb_vm_check_redefinition_by_prepend(klass); } if (RB_TYPE_P(klass, T_MODULE)) { - rb_subclass_entry_t *iclass = RCLASS_EXT(klass)->subclasses; + rb_subclass_entry_t *iclass = RCLASS_SUBCLASSES(klass); VALUE klass_origin = RCLASS_ORIGIN(klass); struct rb_id_table *klass_m_tbl = RCLASS_M_TBL(klass); struct rb_id_table *klass_origin_m_tbl = RCLASS_M_TBL(klass_origin); diff --git a/gc.c b/gc.c index ad44859..b1e115f 100644 --- a/gc.c +++ b/gc.c @@ -2836,14 +2836,14 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L2836 if (RCLASS_IV_INDEX_TBL(obj)) { iv_index_tbl_free(RCLASS_IV_INDEX_TBL(obj)); } - if (RCLASS_EXT(obj)->subclasses) { + if (RCLASS_SUBCLASSES(obj)) { if (BUILTIN_TYPE(obj) == T_MODULE) { rb_class_detach_module_subclasses(obj); } else { rb_class_detach_subclasses(obj); } - RCLASS_EXT(obj)->subclasses = NULL; + RCLASS_SUBCLASSES(obj) = NULL; } rb_class_remove_from_module_subclasses(obj); rb_class_remove_from_super_subclasses(obj); @@ -3008,9 +3008,9 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3008 if (RCLASS_CALLABLE_M_TBL(obj) != NULL) { rb_id_table_free(RCLASS_CALLABLE_M_TBL(obj)); } - if (RCLASS_EXT(obj)->subclasses) { + if (RCLASS_SUBCLASSES(obj)) { rb_class_detach_subclasses(obj); - RCLASS_EXT(obj)->subclasses = NULL; + RCLASS_SUBCLASSES(obj) = NULL; } cc_table_free(objspace, obj, FALSE); rb_class_remove_from_module_subclasses(obj); diff --git a/internal/class.h b/internal/class.h index b05e264..6c03a31 100644 --- a/internal/class.h +++ b/internal/class.h @@ -95,6 +95,7 @@ typedef struct rb_classext_struct rb_classext_t; https://github.com/ruby/ruby/blob/trunk/internal/class.h#L95 #define RCLASS_PARENT_SUBCLASSES(c) (RCLASS_EXT(c)->parent_subclasses) #define RCLASS_MODULE_SUBCLASSES(c) (RCLASS_EXT(c)->module_subclasses) #define RCLASS_ALLOCATOR(c) (RCLASS_EXT(c)->allocator) +#define RCLASS_SUBCLASSES(c) (RCLASS_EXT(c)->subclasses) #define RICLASS_IS_ORIGIN FL_USER5 #define RCLASS_CLONED FL_USER6 diff --git a/vm_method.c b/vm_method.c index 19852b0..45285e0 100644 --- a/vm_method.c +++ b/vm_method.c @@ -153,7 +153,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L153 VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_ICLASS)); if (rb_objspace_garbage_object_p(klass)) return; - if (LIKELY(RCLASS_EXT(klass)->subclasses == NULL)) { + if (LIKELY(RCLASS_SUBCLASSES(klass) == NULL)) { // no subclasses // check only current class -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/