Skip to content

Commit b0502e8

Browse files
committed
Remove respond_to check from Class#bind_call
1 parent c652854 commit b0502e8

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

benchmark/object_allocate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ benchmark:
4545
allocate_kwarg_params: "KWArg.new(a: 1, b: 2, c: 3, d: 4)"
4646
allocate_mixed_params: "Mixed.new(1, 2, c: 3, d: 4)"
4747
allocate_no_params: "Object.new"
48+
allocate_allocate: "Object.allocate"
4849
loop_count: 100000

object.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,17 +2138,6 @@ static VALUE class_call_alloc_func(rb_alloc_func_t allocator, VALUE klass);
21382138
*
21392139
*/
21402140

2141-
static VALUE
2142-
rb_class_alloc_m(VALUE klass)
2143-
{
2144-
rb_alloc_func_t allocator = class_get_alloc_func(klass);
2145-
if (!rb_obj_respond_to(klass, rb_intern("allocate"), 1)) {
2146-
rb_raise(rb_eTypeError, "calling %"PRIsVALUE".allocate is prohibited",
2147-
klass);
2148-
}
2149-
return class_call_alloc_func(allocator, klass);
2150-
}
2151-
21522141
static VALUE
21532142
rb_class_alloc(VALUE klass)
21542143
{
@@ -4603,8 +4592,8 @@ InitVM_Object(void)
46034592
rb_define_method(rb_cModule, "deprecate_constant", rb_mod_deprecate_constant, -1); /* in variable.c */
46044593
rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0);
46054594

4606-
rb_define_method(rb_singleton_class(rb_cClass), "allocate", rb_class_alloc_m, 0);
4607-
rb_define_method(rb_cClass, "allocate", rb_class_alloc_m, 0);
4595+
rb_define_method(rb_singleton_class(rb_cClass), "allocate", rb_class_alloc, 0);
4596+
rb_define_method(rb_cClass, "allocate", rb_class_alloc, 0);
46084597
rb_define_method(rb_cClass, "new", rb_class_new_instance_pass_kw, -1);
46094598
rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
46104599
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);

test/ruby/test_class.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,8 @@ def test_uninitialized
283283
assert_raise(TypeError, bug6863) { Class.new(Class.allocate) }
284284

285285
allocator = Class.instance_method(:allocate)
286-
assert_raise_with_message(TypeError, /prohibited/) {
287-
allocator.bind(Rational).call
288-
}
289-
assert_raise_with_message(TypeError, /prohibited/) {
290-
allocator.bind_call(Rational)
291-
}
286+
assert_nothing_raised { allocator.bind(Rational).call }
287+
assert_nothing_raised { allocator.bind_call(Rational) }
292288
end
293289

294290
def test_nonascii_name

0 commit comments

Comments
 (0)