Skip to content

Commit

Permalink
add a generic get_init in expression to avoid check case by case
Browse files Browse the repository at this point in the history
specialize it in ConcatString to optimize a bit cases like:
string s = s1 + s2;
  • Loading branch information
NotFound committed Nov 20, 2011
1 parent 5a3ca89 commit 59837f8
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions winxedst1.winxed
Expand Up @@ -3175,6 +3175,12 @@ class Expr : CommonBase
return self;
}
function cantailcall() { return false; }
function emit_init(e, string result)
{
// By default does the same as plane emit, some expressions
// can override it for optimization.
self.emit(e, result);
}
function emit_get(e)
{
string type = self.checkresult();
Expand Down Expand Up @@ -5175,6 +5181,15 @@ class ConcatString : FinalExpr
e.emitconcat1(auxreg, regvalues[i]);
return auxreg;
}
function emit_init(e, string result)
{
var regvalues = self.getregs(e);
int nvalues = elements(regvalues);
self.annotate(e);
e.emitconcat(result, regvalues[0], regvalues[1]);
for (int i = 2; i < nvalues; ++i)
e.emitconcat1(result, regvalues[i]);
}
function emit_concat_to(e, string result)
{
var regvalues = self.getregs(e);
Expand Down Expand Up @@ -6278,10 +6293,6 @@ class MemberExpr : MemberExprBase
self.annotate(e);
e.say(INDENT, 'getattribute ', result, ', ', obj, ", '", ident, "'");
}
function emit_init(e, string result)
{
self.emit(e, result);
}
function emit_assign(e, string typeright, string rreg)
{
string obj = self.__emit_get_left(e);
Expand Down Expand Up @@ -6821,10 +6832,6 @@ class NewExpr : NewBaseExpr
e.emitset(result, regnew);
}
}
function emit_init(e, string result)
{
return self.emit(e, result, true);
}
}

//**********************************************************************
Expand Down Expand Up @@ -8685,7 +8692,7 @@ class DeclareSingleStatement : DeclareBase
else {
string itype = init.checkresult();
if (itype == basetype)
init.emit(e, reg);
init.emit_init(e, reg);
else {
if (init instanceof IndexExpr) {
// Use the declared type for the indexing
Expand Down Expand Up @@ -9051,10 +9058,7 @@ class VarStatement : VarBaseStatement
if (init != null) {
switch (init.checkresult()) {
case REGvar:
if ((init instanceof MemberExpr) || (init instanceof ArrayExpr) || (init instanceof NewExpr))
init.emit_init(e, reg);
else
init.emit(e, reg);
init.emit_init(e, reg);
break;
case REGstring:
case REGint:
Expand Down

0 comments on commit 59837f8

Please sign in to comment.