Skip to content

Commit

Permalink
Merge pull request #3581 from 9rnsr/fix12798
Browse files Browse the repository at this point in the history
Issue 12798 - constant folding should optimize subsequent concatenations
  • Loading branch information
WalterBright committed May 25, 2014
2 parents a38d877 + 5920f09 commit 99ccc90
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/optimize.c
Expand Up @@ -1212,6 +1212,21 @@ Expression *Expression_optimize(Expression *e, int result, bool keepLvalue)
//printf("CatExp::optimize(%d) %s\n", result, e->toChars());
e->e1 = e->e1->optimize(result);
e->e2 = e->e2->optimize(result);

if (e->e1->op == TOKcat)
{
// Bugzilla 12798: optimize ((expr ~ str1) ~ str2)
CatExp *ce1 = (CatExp *)e->e1;
CatExp cex(e->loc, ce1->e2, e->e2);
cex.type = e->type;
Expression *ex = cex.optimize(result);
if (ex != &cex)
{
e->e1 = ce1->e1;
e->e2 = ex;
}
}

ret = Cat(e->type, e->e1, e->e2);
if (ret == EXP_CANT_INTERPRET)
ret = e;
Expand Down

0 comments on commit 99ccc90

Please sign in to comment.