Simplify empty hahs with DSTAR
This commit is contained in:
parent
a4406bc89a
commit
4b01983bf8
16
parse.y
16
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) %*/
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user