mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add RCLASS_SUBCLASSES Macro
This commit is contained in:
parent
7341b01465
commit
e0f999a2ed
Notes:
git
2021-02-02 01:43:30 +09:00
4 changed files with 16 additions and 15 deletions
20
class.c
20
class.c
|
@ -53,14 +53,14 @@ rb_class_subclass_add(VALUE super, VALUE klass)
|
|||
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)
|
|||
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)
|
|||
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)
|
|||
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)
|
|||
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)
|
|||
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);
|
||||
|
|
8
gc.c
8
gc.c
|
@ -2836,14 +2836,14 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
|
|||
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)
|
|||
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);
|
||||
|
|
|
@ -95,6 +95,7 @@ typedef struct rb_classext_struct rb_classext_t;
|
|||
#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
|
||||
|
|
|
@ -153,7 +153,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid)
|
|||
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue