aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorMarc-André Lafortune <github@marc-andre.ca>2020-12-24 12:08:12 -0500
committerGitHub <noreply@github.com>2020-12-25 02:08:12 +0900
commitdb2ebbd71b746734b88832b1e70db8afed3d68ed (patch)
treeab48ce3cc5083b59ef7858ec9ecadc2ce018fc70 /hash.c
parent8981a63f12f9c30e9c6f893d292d01fd5df89991 (diff)
downloadruby-db2ebbd71b746734b88832b1e70db8afed3d68ed.tar.gz
Optimize calls to `Kernel#hash` (#3987)
This avoids recursive checks when the `hash` method of an object isn't specialized.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c6
1 files changed, 5 insertions, 1 deletions
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)) {