05a6c9c
From 8944a064d0fd7947b8c2b6c761be3e3a0c9073af Mon Sep 17 00:00:00 2001
05a6c9c
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
05a6c9c
Date: Fri, 22 Dec 2023 14:16:48 +0100
05a6c9c
Subject: [PATCH 1/2] Revert "compare_by_identity: remove alloc for non-empty
05a6c9c
 Hash"
05a6c9c
05a6c9c
This reverts commit 11fa76b1b521072c200c78ea023960221ff426d6.
05a6c9c
---
05a6c9c
 hash.c | 13 ++++---------
05a6c9c
 1 file changed, 4 insertions(+), 9 deletions(-)
05a6c9c
05a6c9c
diff --git a/hash.c b/hash.c
05a6c9c
index 78e9d9a2d6..f6525ba4a5 100644
05a6c9c
--- a/hash.c
05a6c9c
+++ b/hash.c
c649282
@@ -4385,16 +4385,13 @@ rb_hash_compare_by_id(VALUE hash)
05a6c9c
     if (hash_iterating_p(hash)) {
05a6c9c
         rb_raise(rb_eRuntimeError, "compare_by_identity during iteration");
05a6c9c
     }
05a6c9c
+    ar_force_convert_table(hash, __FILE__, __LINE__);
05a6c9c
+    HASH_ASSERT(RHASH_ST_TABLE_P(hash));
05a6c9c
 
05a6c9c
     if (RHASH_TABLE_EMPTY_P(hash)) {
05a6c9c
         // Fast path: There's nothing to rehash, so we don't need a `tmp` table.
05a6c9c
-        // We're most likely an AR table, so this will need an allocation.
05a6c9c
-        ar_force_convert_table(hash, __FILE__, __LINE__);
05a6c9c
-        HASH_ASSERT(RHASH_ST_TABLE_P(hash));
05a6c9c
-
05a6c9c
         RHASH_ST_TABLE(hash)->type = &identhash;
05a6c9c
-    }
05a6c9c
-    else {
05a6c9c
+    } else {
05a6c9c
         // Slow path: Need to rehash the members of `self` into a new
05a6c9c
         // `tmp` table using the new `identhash` compare/hash functions.
05a6c9c
         tmp = hash_alloc(0);
c649282
@@ -4402,10 +4399,8 @@ rb_hash_compare_by_id(VALUE hash)
05a6c9c
         identtable = RHASH_ST_TABLE(tmp);
05a6c9c
 
05a6c9c
         rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)tmp);
05a6c9c
-        rb_hash_free(hash);
05a6c9c
 
05a6c9c
-        // We know for sure `identtable` is an st table,
05a6c9c
-        // so we can skip `ar_force_convert_table` here.
05a6c9c
+        rb_hash_free(hash);
05a6c9c
         RHASH_ST_TABLE_SET(hash, identtable);
05a6c9c
         RHASH_ST_CLEAR(tmp);
05a6c9c
     }
05a6c9c
05a6c9c
From f5c415300ffe63e41e46c6b88b8634a3bad0c7c2 Mon Sep 17 00:00:00 2001
05a6c9c
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
05a6c9c
Date: Fri, 22 Dec 2023 14:17:14 +0100
05a6c9c
Subject: [PATCH 2/2] Revert "compare_by_identity: remove alloc for empty Hash"
05a6c9c
05a6c9c
This reverts commit b5c6c0122f5b010cb5f43e7a236c4ba2b1d56a2a.
05a6c9c
---
05a6c9c
 hash.c | 21 +++++++--------------
05a6c9c
 1 file changed, 7 insertions(+), 14 deletions(-)
05a6c9c
05a6c9c
diff --git a/hash.c b/hash.c
05a6c9c
index f6525ba4a5..cf83675c70 100644
05a6c9c
--- a/hash.c
05a6c9c
+++ b/hash.c
c649282
@@ -4388,22 +4388,15 @@ rb_hash_compare_by_id(VALUE hash)
05a6c9c
     ar_force_convert_table(hash, __FILE__, __LINE__);
05a6c9c
     HASH_ASSERT(RHASH_ST_TABLE_P(hash));
05a6c9c
 
05a6c9c
-    if (RHASH_TABLE_EMPTY_P(hash)) {
05a6c9c
-        // Fast path: There's nothing to rehash, so we don't need a `tmp` table.
05a6c9c
-        RHASH_ST_TABLE(hash)->type = &identhash;
05a6c9c
-    } else {
05a6c9c
-        // Slow path: Need to rehash the members of `self` into a new
05a6c9c
-        // `tmp` table using the new `identhash` compare/hash functions.
05a6c9c
-        tmp = hash_alloc(0);
05a6c9c
-        hash_st_table_init(tmp, &identhash, RHASH_SIZE(hash));
05a6c9c
-        identtable = RHASH_ST_TABLE(tmp);
05a6c9c
+    tmp = hash_alloc(0);
05a6c9c
+    hash_st_table_init(tmp, &identhash, RHASH_SIZE(hash));
05a6c9c
+    identtable = RHASH_ST_TABLE(tmp);
05a6c9c
 
05a6c9c
-        rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)tmp);
05a6c9c
+    rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)tmp);
05a6c9c
 
05a6c9c
-        rb_hash_free(hash);
05a6c9c
-        RHASH_ST_TABLE_SET(hash, identtable);
05a6c9c
-        RHASH_ST_CLEAR(tmp);
05a6c9c
-    }
05a6c9c
+    rb_hash_free(hash);
05a6c9c
+    RHASH_ST_TABLE_SET(hash, identtable);
05a6c9c
+    RHASH_ST_CLEAR(tmp);
05a6c9c
 
05a6c9c
     return hash;
05a6c9c
 }