mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
compile.c: optimize local variable assignments
* compile.c (iseq_peephole_optimize): eliminate simple self assignments of a local variable when the result is used. follow-up of r60322. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f644d3ef67
commit
72f88ebcc1
1 changed files with 7 additions and 3 deletions
10
compile.c
10
compile.c
|
@ -2597,12 +2597,16 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
|
|||
}
|
||||
|
||||
if (IS_INSN_ID(iobj, getlocal)) {
|
||||
if (IS_NEXT_INSN_ID(&iobj->link, setlocal)) {
|
||||
LINK_ELEMENT *set1 = iobj->link.next;
|
||||
LINK_ELEMENT *niobj = &iobj->link;
|
||||
if (IS_NEXT_INSN_ID(niobj, dup)) {
|
||||
niobj = niobj->next;
|
||||
}
|
||||
if (IS_NEXT_INSN_ID(niobj, setlocal)) {
|
||||
LINK_ELEMENT *set1 = niobj->next;
|
||||
if (OPERAND_AT(iobj, 0) == OPERAND_AT(set1, 0) &&
|
||||
OPERAND_AT(iobj, 1) == OPERAND_AT(set1, 1)) {
|
||||
REMOVE_ELEM(set1);
|
||||
REMOVE_ELEM(&iobj->link);
|
||||
REMOVE_ELEM(niobj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue