Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit cc3ad15

Browse files
hkielOpenModelica-Hudson
authored andcommitted
avoid creation of temporary lists
1 parent 1c87ab0 commit cc3ad15

17 files changed

+123
-82
lines changed

Compiler/BackEnd/BackendDump.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,7 +4299,7 @@ algorithm
42994299
end for;//end comps
43004300

43014301
//dump edges
4302-
for eqIdx in List.intRange(arrayLength(m)) loop
4302+
for eqIdx in 1:arrayLength(m) loop
43034303
for varIdx in arrayGet(m, eqIdx) loop
43044304
if intLe(varIdx, 0) then
43054305
lineType := GraphML.DASHED();
@@ -4400,7 +4400,7 @@ protected
44004400
Integer i;
44014401
String s1;
44024402
algorithm
4403-
for i in List.intRange(arrayLength(constraints)) loop
4403+
for i in 1:arrayLength(constraints) loop
44044404
s1 := stringDelimitList(List.map(arrayGet(constraints,i),BackendDump.equationString),"\n")+"\n------------------\n";
44054405
if listEmpty(arrayGet(constraints,i)) then
44064406
s1 := "empty Constraints\n";

Compiler/BackEnd/Differentiate.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ protected
29392939
algorithm
29402940
b[1] := Types.isRealOrSubTypeReal(inType);
29412941
b[2] := Types.isRecord(inType);
2942-
out := Util.boolOrList({b[1],b[2]});
2942+
out := boolOr(b[1],b[2]);
29432943
end diffableTypes;
29442944

29452945

Compiler/BackEnd/EvaluateFunctions.mo

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ algorithm
20162016
stmt1 = if isCon then DAE.STMT_ASSIGN(typ,exp1,exp2,source) else stmt;
20172017
tplExpsLHS = if isTpl then Expression.getComplexContents(exp1) else {};
20182018
tplExpsRHS = if isTpl then Expression.getComplexContents(exp2) else {};
2019-
tplStmts = List.map2(List.intRange(listLength(tplExpsLHS)),makeAssignmentMap,tplExpsLHS,tplExpsRHS);
2019+
tplStmts = makeAssignmentMap(tplExpsLHS,tplExpsRHS);
20202020
stmts1 = if isTpl then tplStmts else {stmt1};
20212021
if Flags.isSet(Flags.EVAL_FUNC_DUMP) then
20222022
print("evaluated assignment to:\n"+stringDelimitList(List.map(stmts1,DAEDump.ppStatementStr),"\n")+"\n");
@@ -2071,7 +2071,7 @@ algorithm
20712071
stmt1 = if isCon then DAE.STMT_ASSIGN(typ,exp1,exp2,source) else stmt;
20722072
tplExpsLHS = if isTpl then Expression.getComplexContents(exp1) else {};
20732073
tplExpsRHS = if isTpl then Expression.getComplexContents(exp2) else {};
2074-
tplStmts = List.map2(List.intRange(listLength(tplExpsLHS)),makeAssignmentMap,tplExpsLHS,tplExpsRHS);
2074+
tplStmts = makeAssignmentMap(tplExpsLHS,tplExpsRHS);
20752075
stmts1 = if isTpl then tplStmts else {stmt1};
20762076
if Flags.isSet(Flags.EVAL_FUNC_DUMP) then
20772077
print("evaluated array assignment to:\n"+stringDelimitList(List.map(stmts1,DAEDump.ppStatementStr),"\n")+"\n");
@@ -2156,7 +2156,7 @@ algorithm
21562156
tplExpsLHS = if isCon then tplExpsLHS else {};
21572157
tplExpsRHS = DAEUtil.getTupleExps(exp1);
21582158
tplExpsRHS = if isCon then tplExpsRHS else {};
2159-
stmtsNew = List.map2(List.intRange(listLength(tplExpsLHS)),makeAssignmentMap,tplExpsLHS,tplExpsRHS); // if the tuple is completely constant
2159+
stmtsNew = makeAssignmentMap(tplExpsLHS,tplExpsRHS); // if the tuple is completely constant
21602160

21612161
stmtsNew = if isCon then stmtsNew else {stmt};
21622162
stmts2 = if intEq(size,0) then {DAE.STMT_ASSIGN(typ,exp2,exp1,DAE.emptyElementSource)} else stmtsNew;
@@ -2552,7 +2552,7 @@ algorithm
25522552
print(" check getStatementLHS for WHEN!\n"+DAEDump.ppStatementStr(stmt));
25532553
end if;
25542554
expLst = List.fold(stmtLst1,getStatementLHS,expsIn);
2555-
expLst = List.fold({stmt1},getStatementLHS,expLst);
2555+
expLst = getStatementLHS(stmt1,expLst);
25562556
then expLst;
25572557
case(DAE.STMT_WHEN(statementLst=stmtLst1,elseWhen=NONE()),_)
25582558
equation
@@ -3159,7 +3159,7 @@ algorithm
31593159
//repl = bcallret3(not predicted, BackendVarTransform.removeReplacements,replIn,varCrefs,NONE(),replIn);
31603160
//bcall(not predicted,print,"remove the replacement for: "+stringDelimitList(List.map(varCrefs,ComponentReference.crefStr),"\n")+"\n");
31613161
// build the additional statements and update the old one
3162-
addStmts = List.map2(List.intRange(listLength(outExps)),makeAssignmentMap,outExps,expLst);
3162+
addStmts = makeAssignmentMap(outExps,expLst);
31633163
stmtNew = updateStatementsInIfStmt(stmtsLst,stmtIn);
31643164

31653165
// print("the new predicted stmts: \n"+stringDelimitList(List.map({stmtNew},DAEDump.ppStatementStr),"\n")+"\nAnd the additional "+stringDelimitList(List.map(addStmts,DAEDump.ppStatementStr),"\n")+"\n");
@@ -3305,50 +3305,40 @@ end updateStatementsInElse;
33053305
protected function compareConstantExps "compares the lists of expressions if there are the same constants at the same position
33063306
author:Waurich TUD 2014-04"
33073307
input list<list<DAE.Exp>> expLstLstIn;
3308-
output list<Integer> posLstOut;
3309-
protected
3310-
Integer num;
3311-
list<Integer> idcs;
3308+
output list<Integer> posLstOut = {};
33123309
algorithm
3313-
num := listLength(listHead(expLstLstIn));
3314-
idcs := List.intRange(num);
3315-
posLstOut := List.fold1(idcs,compareConstantExps2,expLstLstIn,{});
3310+
for i in 1:listLength(listHead(expLstLstIn)) loop
3311+
posLstOut := compareConstantExps2(i, expLstLstIn, posLstOut);
3312+
end for;
33163313
end compareConstantExps;
33173314

33183315
protected function compareConstantExps2
33193316
input Integer idx;
33203317
input list<list<DAE.Exp>> expLstLst;
3321-
input list<Integer> posIn;
3322-
output list<Integer> posOut;
3318+
input output list<Integer> pos;
33233319
protected
33243320
Boolean b1,b2;
3325-
list<Boolean> bLst;
3326-
list<Integer> posLst;
33273321
DAE.Exp firstExp;
33283322
list<DAE.Exp> expLst,rest;
33293323
algorithm
33303324
expLst := List.map1(expLstLst,listGet,idx);
3331-
firstExp::rest := expLst;
3332-
bLst := List.map(expLst,Expression.isConst);
3333-
b1 := List.fold(bLst,boolAnd,true);
3334-
bLst := List.map1(rest,Expression.expEqual,firstExp);
3335-
b2 := List.fold(bLst,boolAnd,true);
3336-
posLst := idx::posIn;
3337-
posOut := if b1 and b2 then posLst else posIn;
3325+
b1 := List.mapBoolAnd(expLst,Expression.isConst);
3326+
if b1 then
3327+
firstExp::rest := expLst;
3328+
b2 := List.map1BoolAnd(rest,Expression.expEqual,firstExp);
3329+
if b2 then
3330+
pos := idx::pos;
3331+
end if;
3332+
end if;
33383333
end compareConstantExps2;
33393334

3340-
protected function makeAssignmentMap "mapping function fo build the statements for a list of lhs and rhs exps.
3335+
protected function makeAssignmentMap "mapping function to build the statements for a list of lhs and rhs exps.
33413336
author:Waurich TUD 2014-04"
3342-
input Integer idx;
33433337
input list<DAE.Exp> lhs;
33443338
input list<DAE.Exp> rhs;
3345-
output DAE.Statement stmt;
3346-
protected
3347-
DAE.Exp e1,e2;
3339+
output list<DAE.Statement> stmts;
33483340
algorithm
3349-
e1 := listGet(lhs,idx);
3350-
e2 := listGet(rhs,idx);
3351-
stmt := makeAssignment(e1,e2);
3341+
stmts := list(makeAssignment(e1, e2) threaded for e1 in lhs, e2 in rhs);
33523342
end makeAssignmentMap;
33533343

33543344
protected function makeAssignment "makes an DAE.STMT_ASSIGN of the 2 DAE.Exp"

Compiler/BackEnd/HpcOmMemory.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ import Util;
21082108
Integer i;
21092109
algorithm
21102110
tmpArray := iArray;
2111-
for i in List.intRange(arrayLength(tmpArray)) loop
2111+
for i in 1:arrayLength(tmpArray) loop
21122112
if(intNe(i, iIndex)) then
21132113
tmpArray := arrayUpdate(tmpArray, i, arrayGet(tmpArray, i) + iOffset);
21142114
end if;

Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4598,7 +4598,7 @@ algorithm
45984598
partCosts := listReverse(partCosts);
45994599
//cluster them and correct task<->partition mapping
46004600
(partitions,_) := HpcOmTaskGraph.distributeToClusters(List.intRange(arrayLength(partMap)),partCosts,n);
4601-
for partIdx in List.intRange(n) loop
4601+
for partIdx in 1:n loop
46024602
part := arrayGet(partitions,partIdx);
46034603
clusters := List.map1(part,Array.getIndexFirst,partMap);
46044604
part := List.fold(clusters,listAppend,{});

Compiler/BackEnd/HpcOmTaskGraph.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6632,7 +6632,7 @@ algorithm
66326632
act := act+1;
66336633
end for;
66346634
print("\n");
6635-
for part in List.intRange(numPartitions) loop
6635+
for part in 1:numPartitions loop
66366636
//print("activators: "+intLstString(listGet(activatorsForPartitions,part))+"\t\t\t\tnodes: \t"+intLstString(listGet(partitions,part))+"\n\n");
66376637
print("activators: "+intLstString(listGet(activatorsForPartitions,part))+"\t\t\t\tderStateTasks: "+intLstString(List.map1(listGet(activatorsForPartitions,part),List.getIndexFirst,stateToActivators))+"\t\t\t\tnodes: \t"+intLstString(listGet(partitions,part))+"\n");
66386638
end for;

Compiler/BackEnd/IndexReduction.mo

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ algorithm
487487
list<Integer> unassignedEqns,eqnsLst,varlst,discEqns;
488488
list<BackendDAE.Var> vlst;
489489
Boolean b,ba;
490-
list<Boolean> blst;
491490
/* case((unassignedEqns,eqnsLst))
492491
equation
493492
vindx = ass2[eindx];
@@ -504,9 +503,8 @@ algorithm
504503
varlst = m[eindx];
505504
varlst = List.map(varlst,intAbs);
506505
vlst = List.map1r(varlst,BackendVariable.getVarAt,vars);
507-
blst = List.map(vlst,BackendVariable.isVarDiscrete);
508-
// if there is a continues variable than b is false
509-
b = Util.boolAndList(blst);
506+
// if there is a continues variable then b is false
507+
b = List.mapBoolAnd(vlst,BackendVariable.isVarDiscrete);
510508
eqnsLst = List.consOnTrue(not b, eindx, eqnsLst);
511509
unassignedEqns = List.consOnTrue(ba and not b, eindx, unassignedEqns);
512510
discEqns = List.consOnTrue(b, eindx, discEqns);

Compiler/BackEnd/OnRelaxation.mo

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ algorithm
715715
list<Integer> rest, roots, constraints, elst, rlst;
716716
Integer o;
717717
Boolean foundflow, constr;
718-
list<Boolean> blst;
719718
list<BackendDAE.Var> vlst;
720719
case ({}, _, _, _, _, _, _, _, _, _, _, _)
721720
then
@@ -730,8 +729,7 @@ algorithm
730729
// check for partner
731730
// BackendDump.debuglst((rlst, intString, ", ", "\n"));
732731
vlst = List.map1r(rlst, BackendVariable.getVarAt, vars);
733-
blst = List.map(vlst, BackendVariable.isFlowVar);
734-
constr = Util.boolAndList(blst);
732+
constr = List.mapBoolAnd(vlst, BackendVariable.isFlowVar);
735733
constraints = List.consOnTrue(constr, o, iconstraints);
736734
// print("Process Orphan " + intString(o) + "\n");
737735
// BackendDump.debuglst((mt[o], intString, ", ", "\n"));
@@ -1034,7 +1032,7 @@ protected
10341032
algorithm
10351033
// print("Add orpan[" + intString(orphan) + "] = " + intString(preorphan) + "\n");
10361034
olst := arr[orphan];
1037-
olst := List.union({preorphan}, olst);
1035+
olst := List.unionElt(preorphan, olst);
10381036
_:=arrayUpdate(arr, orphan, olst);
10391037
end addPreOrphan;
10401038

@@ -3241,7 +3239,6 @@ algorithm
32413239
list<DAE.ComponentRef> crlst, crlst1;
32423240
list<DAE.Exp> elst;
32433241
list<Integer> ilst;
3244-
list<Boolean> blst;
32453242
HashSet.HashSet set;
32463243

32473244
// a = f(...)
@@ -3310,8 +3307,7 @@ algorithm
33103307
crlst = List.uniqueOnTrue(crlst, ComponentReference.crefEqualNoStringCompare);
33113308
true = intEq(size, listLength(crlst));
33123309
cr::crlst1 = crlst;
3313-
blst = List.map1(crlst1, ComponentReference.crefEqualWithoutLastSubs, cr);
3314-
true = Util.boolAndList(blst);
3310+
true = List.map1BoolAnd(crlst1, ComponentReference.crefEqualWithoutLastSubs, cr);
33153311
// check if crefs no on other side
33163312
set = HashSet.emptyHashSet();
33173313
crnosubs = ComponentReference.crefStripLastSubs(cr);
@@ -3334,8 +3330,7 @@ algorithm
33343330
crlst = List.uniqueOnTrue(crlst, ComponentReference.crefEqualNoStringCompare);
33353331
true = intEq(size, listLength(crlst));
33363332
cr::crlst1 = crlst;
3337-
blst = List.map1(crlst1, ComponentReference.crefEqualWithoutLastSubs, cr);
3338-
true = Util.boolAndList(blst);
3333+
true = List.map1BoolAnd(crlst1, ComponentReference.crefEqualWithoutLastSubs, cr);
33393334
// check if crefs no on other side
33403335
set = HashSet.emptyHashSet();
33413336
crnosubs = ComponentReference.crefStripLastSubs(cr);

Compiler/BackEnd/SymbolicJacobian.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,7 @@ algorithm
26062606
case DAE.T_ARRAY(ty=ty) then isRecordInvoled(ty);
26072607
case DAE.T_FUNCTION(funcResultType=ty) then isRecordInvoled(ty);
26082608
case DAE.T_TUPLE(types)
2609-
then Util.boolOrList(List.map(types, isRecordInvoled));
2609+
then List.mapBoolOr(types, isRecordInvoled);
26102610
else false;
26112611
end match;
26122612
end isRecordInvoled;

Compiler/FrontEnd/Algorithm.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public function makeTupleAssignmentNoTypeCheck
136136
protected
137137
Boolean b1,b2;
138138
algorithm
139-
b1 := List.applyAndFold(lhs, boolAnd, Expression.isWild, true);
140-
b2 := List.applyAndFold(List.restOrEmpty(lhs), boolAnd, Expression.isWild, true);
139+
b1 := List.mapBoolAnd(lhs, Expression.isWild);
140+
b2 := List.mapBoolAnd(List.restOrEmpty(lhs), Expression.isWild);
141141
outStatement := makeTupleAssignmentNoTypeCheck2(b1,b2,ty,lhs,rhs,source);
142142
end makeTupleAssignmentNoTypeCheck;
143143

0 commit comments

Comments
 (0)