Use flag for RCLASS_IS_INITIALIZED

Previously we used a flag to set whether a module was uninitialized.
When checked whether a class was initialized, we first had to check that
it had a non-zero superclass, as well as that it wasn't BasicObject.

With the advent of namespaces, RCLASS_SUPER is now an expensive
operation, and though we could just check for the prime superclass, we
might as well take this opportunity to use a flag so that we can perform
the initialized check with as few instructions as possible.

It's possible in the future that we could prevent uninitialized classes
from being available to the user, but currently there are a few ways to
do that.
This commit is contained in:
John Hawthorn 2025-05-26 11:48:41 -07:00
parent 3935b1c401
commit d1343e12d2
Notes: git 2025-05-28 15:44:19 +00:00
7 changed files with 41 additions and 30 deletions

View file

@ -2069,7 +2069,7 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
else {
super = argv[0];
rb_check_inheritable(super);
if (super != rb_cBasicObject && !RCLASS_SUPER(super)) {
if (!RCLASS_INITIALIZED_P(super)) {
rb_raise(rb_eTypeError, "can't inherit uninitialized class");
}
}
@ -2126,7 +2126,7 @@ class_get_alloc_func(VALUE klass)
{
rb_alloc_func_t allocator;
if (RCLASS_SUPER(klass) == 0 && klass != rb_cBasicObject) {
if (!RCLASS_INITIALIZED_P(klass)) {
rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
}
if (RCLASS_SINGLETON_P(klass)) {