From db2ebbd71b746734b88832b1e70db8afed3d68ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lafortune?= Date: Thu, 24 Dec 2020 12:08:12 -0500 Subject: Optimize calls to `Kernel#hash` (#3987) This avoids recursive checks when the `hash` method of an object isn't specialized. --- hash.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 9b4c315a09..c3a512b8e9 100644 --- a/hash.c +++ b/hash.c @@ -142,7 +142,11 @@ hash_recursive(VALUE obj, VALUE arg, int recurse) VALUE rb_hash(VALUE obj) { - VALUE hval = rb_exec_recursive_outer(hash_recursive, obj, 0); + VALUE hval = rb_check_funcall_basic_kw(obj, id_hash, rb_mKernel, 0, 0, 0); + + if (hval == Qundef) { + hval = rb_exec_recursive_outer(hash_recursive, obj, 0); + } while (!FIXNUM_P(hval)) { if (RB_TYPE_P(hval, T_BIGNUM)) { -- cgit v1.2.3