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.
This commit is contained in:
Peter Zhu 2023-02-02 09:43:38 -05:00
Родитель f901b934fd
Коммит e30cf60a19
1 изменённых файлов: 17 добавлений и 33 удалений

50
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