diff options
| author | John Hawthorn <john@hawthorn.email> | 2025-12-05 23:32:15 -0800 |
|---|---|---|
| committer | John Hawthorn <john@hawthorn.email> | 2025-12-11 09:53:10 -0800 |
| commit | 459c377222e746a5e39756bf5d648d16893e831c (patch) | |
| tree | 69a69d9568d2b2e765f6942489baa412b5f9bb77 /object.c | |
| parent | b5604833a37bf8cac132906fbf8297d6d4ae9976 (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.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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; } |
