From 4b01983bf81259e3d1837b4c8a27c440c0278403 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 9 Jan 2024 13:05:34 +0900 Subject: [PATCH] Simplify empty hahs with DSTAR --- parse.y | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/parse.y b/parse.y index 2ac575ca7f..0ddf12acce 100644 --- a/parse.y +++ b/parse.y @@ -6858,7 +6858,9 @@ assocs : assoc tail = RNODE_HASH(n)->nd_head; } } - assocs = list_concat(assocs, tail); + if (tail) { + assocs = list_concat(assocs, tail); + } } $$ = assocs; /*% %*/ @@ -6900,17 +6902,7 @@ assoc : arg_value tASSOC arg_value | tDSTAR arg_value { /*%%%*/ - if (nd_type_p($2, NODE_HASH) && - !(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); + $$ = list_append(p, NEW_LIST(0, &@$), $2); /*% %*/ /*% ripper: assoc_splat!($2) %*/ }