summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2025-12-05 23:32:15 -0800
committerJohn Hawthorn <john@hawthorn.email>2025-12-11 09:53:10 -0800
commit459c377222e746a5e39756bf5d648d16893e831c (patch)
tree69a69d9568d2b2e765f6942489baa412b5f9bb77 /object.c
parentb5604833a37bf8cac132906fbf8297d6d4ae9976 (diff)
Assume result from allocator will be valid
This adds a fastpath in class_call_alloc_func to simply return if the class matches the one expected. I think we could probably just remove this check, or move it to the debug build.
Diffstat (limited to 'object.c')
-rw-r--r--object.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/object.c b/object.c
index bcafab3c3d..158bb0b219 100644
--- a/object.c
+++ b/object.c
@@ -2238,8 +2238,10 @@ class_call_alloc_func(rb_alloc_func_t allocator, VALUE klass)
obj = (*allocator)(klass);
- if (rb_obj_class(obj) != rb_class_real(klass)) {
- rb_raise(rb_eTypeError, "wrong instance allocation");
+ if (UNLIKELY(RBASIC_CLASS(obj) != klass)) {
+ if (rb_obj_class(obj) != rb_class_real(klass)) {
+ rb_raise(rb_eTypeError, "wrong instance allocation");
+ }
}
return obj;
}