From e30cf60a191ab78d08930825598026e85e130648 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Thu, 2 Feb 2023 09:43:38 -0500 Subject: [PATCH] Remove dead code in ar_copy All of the callers of ar_copy guarantee that hash2 has an ar table, so we don't need the logic to handle the case when hash2 doesn't have an ar table. --- hash.c | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/hash.c b/hash.c index ac41e08cc8..463ef498e5 100644 --- a/hash.c +++ b/hash.c @@ -1199,44 +1199,28 @@ static ar_table* ar_copy(VALUE hash1, VALUE hash2) { ar_table *old_tab = RHASH_AR_TABLE(hash2); + ar_table *new_tab = RHASH_AR_TABLE(hash1); - if (old_tab != NULL) { - ar_table *new_tab = RHASH_AR_TABLE(hash1); - if (new_tab == NULL) { - new_tab = (ar_table*) rb_transient_heap_alloc(hash1, sizeof(ar_table)); - if (new_tab != NULL) { - RHASH_SET_TRANSIENT_FLAG(hash1); - } - else { - RHASH_UNSET_TRANSIENT_FLAG(hash1); - new_tab = (ar_table*)ruby_xmalloc(sizeof(ar_table)); - } + if (new_tab == NULL) { + new_tab = (ar_table*) rb_transient_heap_alloc(hash1, sizeof(ar_table)); + if (new_tab != NULL) { + RHASH_SET_TRANSIENT_FLAG(hash1); } - *new_tab = *old_tab; - RHASH(hash1)->ar_hint.word = RHASH(hash2)->ar_hint.word; - RHASH_AR_TABLE_BOUND_SET(hash1, RHASH_AR_TABLE_BOUND(hash2)); - RHASH_AR_TABLE_SIZE_SET(hash1, RHASH_AR_TABLE_SIZE(hash2)); - hash_ar_table_set(hash1, new_tab); - - rb_gc_writebarrier_remember(hash1); - return new_tab; - } - else { - RHASH_AR_TABLE_BOUND_SET(hash1, RHASH_AR_TABLE_BOUND(hash2)); - RHASH_AR_TABLE_SIZE_SET(hash1, RHASH_AR_TABLE_SIZE(hash2)); - - if (RHASH_TRANSIENT_P(hash1)) { + else { RHASH_UNSET_TRANSIENT_FLAG(hash1); + new_tab = (ar_table*)ruby_xmalloc(sizeof(ar_table)); } - else if (RHASH_AR_TABLE(hash1)) { - ruby_xfree(RHASH_AR_TABLE(hash1)); - } - - hash_ar_table_set(hash1, NULL); - - rb_gc_writebarrier_remember(hash1); - return old_tab; } + + *new_tab = *old_tab; + RHASH(hash1)->ar_hint.word = RHASH(hash2)->ar_hint.word; + RHASH_AR_TABLE_BOUND_SET(hash1, RHASH_AR_TABLE_BOUND(hash2)); + RHASH_AR_TABLE_SIZE_SET(hash1, RHASH_AR_TABLE_SIZE(hash2)); + hash_ar_table_set(hash1, new_tab); + + rb_gc_writebarrier_remember(hash1); + + return new_tab; } static void