Simplify empty hahs with DSTAR

This commit is contained in:
Nobuyoshi Nakada 2024-01-09 13:05:34 +09:00
parent a4406bc89a
commit 4b01983bf8
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465

16
parse.y
View File

@ -6858,7 +6858,9 @@ assocs : assoc
tail = RNODE_HASH(n)->nd_head; tail = RNODE_HASH(n)->nd_head;
} }
} }
assocs = list_concat(assocs, tail); if (tail) {
assocs = list_concat(assocs, tail);
}
} }
$$ = assocs; $$ = assocs;
/*% %*/ /*% %*/
@ -6900,17 +6902,7 @@ assoc : arg_value tASSOC arg_value
| tDSTAR arg_value | tDSTAR arg_value
{ {
/*%%%*/ /*%%%*/
if (nd_type_p($2, NODE_HASH) && $$ = list_append(p, NEW_LIST(0, &@$), $2);
!(RNODE_HASH($2)->nd_head && RNODE_LIST(RNODE_HASH($2)->nd_head)->as.nd_alen)) {
static VALUE empty_hash;
if (!empty_hash) {
empty_hash = rb_obj_freeze(rb_hash_new());
rb_gc_register_mark_object(empty_hash);
}
$$ = list_append(p, NEW_LIST(0, &@$), NEW_LIT(empty_hash, &@$));
}
else
$$ = list_append(p, NEW_LIST(0, &@$), $2);
/*% %*/ /*% %*/
/*% ripper: assoc_splat!($2) %*/ /*% ripper: assoc_splat!($2) %*/
} }