mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Optimize duparray/expandarray -> putobject/expandarray
There's no point in making a copy of an array just to expand it. Saves an unnecessary array allocation in the multiple assignment case, with a 35-84% improvement in affected cases in benchmark/masgn.yml.
This commit is contained in:
parent
fc4b4f2e8d
commit
9363b0423a
Notes:
git
2022-08-10 14:20:07 +09:00
1 changed files with 14 additions and 0 deletions
14
compile.c
14
compile.c
|
@ -3396,6 +3396,20 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
|
|||
}
|
||||
}
|
||||
|
||||
if (IS_INSN_ID(iobj, duparray)) {
|
||||
LINK_ELEMENT *next = iobj->link.next;
|
||||
/*
|
||||
* duparray obj
|
||||
* expandarray X, 0
|
||||
* =>
|
||||
* putobject obj
|
||||
* expandarray X, 0
|
||||
*/
|
||||
if (IS_INSN(next) && IS_INSN_ID(next, expandarray)) {
|
||||
INSN_OF(iobj) = BIN(putobject);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_INSN_ID(iobj, anytostring)) {
|
||||
LINK_ELEMENT *next = iobj->link.next;
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue