Skip to content

Commit e30cf60

Browse files
committed
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.
1 parent f901b93 commit e30cf60

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

hash.c

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,44 +1199,28 @@ static ar_table*
11991199
ar_copy(VALUE hash1, VALUE hash2)
12001200
{
12011201
ar_table *old_tab = RHASH_AR_TABLE(hash2);
1202+
ar_table *new_tab = RHASH_AR_TABLE(hash1);
12021203

1203-
if (old_tab != NULL) {
1204-
ar_table *new_tab = RHASH_AR_TABLE(hash1);
1205-
if (new_tab == NULL) {
1206-
new_tab = (ar_table*) rb_transient_heap_alloc(hash1, sizeof(ar_table));
1207-
if (new_tab != NULL) {
1208-
RHASH_SET_TRANSIENT_FLAG(hash1);
1209-
}
1210-
else {
1211-
RHASH_UNSET_TRANSIENT_FLAG(hash1);
1212-
new_tab = (ar_table*)ruby_xmalloc(sizeof(ar_table));
1213-
}
1204+
if (new_tab == NULL) {
1205+
new_tab = (ar_table*) rb_transient_heap_alloc(hash1, sizeof(ar_table));
1206+
if (new_tab != NULL) {
1207+
RHASH_SET_TRANSIENT_FLAG(hash1);
12141208
}
1215-
*new_tab = *old_tab;
1216-
RHASH(hash1)->ar_hint.word = RHASH(hash2)->ar_hint.word;
1217-
RHASH_AR_TABLE_BOUND_SET(hash1, RHASH_AR_TABLE_BOUND(hash2));
1218-
RHASH_AR_TABLE_SIZE_SET(hash1, RHASH_AR_TABLE_SIZE(hash2));
1219-
hash_ar_table_set(hash1, new_tab);
1220-
1221-
rb_gc_writebarrier_remember(hash1);
1222-
return new_tab;
1223-
}
1224-
else {
1225-
RHASH_AR_TABLE_BOUND_SET(hash1, RHASH_AR_TABLE_BOUND(hash2));
1226-
RHASH_AR_TABLE_SIZE_SET(hash1, RHASH_AR_TABLE_SIZE(hash2));
1227-
1228-
if (RHASH_TRANSIENT_P(hash1)) {
1209+
else {
12291210
RHASH_UNSET_TRANSIENT_FLAG(hash1);
1211+
new_tab = (ar_table*)ruby_xmalloc(sizeof(ar_table));
12301212
}
1231-
else if (RHASH_AR_TABLE(hash1)) {
1232-
ruby_xfree(RHASH_AR_TABLE(hash1));
1233-
}
1213+
}
12341214

1235-
hash_ar_table_set(hash1, NULL);
1215+
*new_tab = *old_tab;
1216+
RHASH(hash1)->ar_hint.word = RHASH(hash2)->ar_hint.word;
1217+
RHASH_AR_TABLE_BOUND_SET(hash1, RHASH_AR_TABLE_BOUND(hash2));
1218+
RHASH_AR_TABLE_SIZE_SET(hash1, RHASH_AR_TABLE_SIZE(hash2));
1219+
hash_ar_table_set(hash1, new_tab);
12361220

1237-
rb_gc_writebarrier_remember(hash1);
1238-
return old_tab;
1239-
}
1221+
rb_gc_writebarrier_remember(hash1);
1222+
1223+
return new_tab;
12401224
}
12411225

12421226
static void

0 commit comments

Comments
 (0)