Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add a generic get_init in expression to avoid check case by case

specialize it in ConcatString to optimize a bit cases like:
string s = s1 + s2;
  • Loading branch information...
commit 59837f82e5550f5569c75164bdad205b2d533bf7 1 parent 5a3ca89
@NotFound authored
Showing with 17 additions and 13 deletions.
  1. +17 −13 winxedst1.winxed
View
30 winxedst1.winxed
@@ -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();
@@ -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);
@@ -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);
@@ -6821,10 +6832,6 @@ class NewExpr : NewBaseExpr
e.emitset(result, regnew);
}
}
- function emit_init(e, string result)
- {
- return self.emit(e, result, true);
- }
}
//**********************************************************************
@@ -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
@@ -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:
Please sign in to comment.
Something went wrong with that request. Please try again.