Skip to content

Commit

Permalink
remove List.appendNoCopy()
Browse files Browse the repository at this point in the history
and replace calls to it by listAppend()
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Apr 13, 2016
1 parent 9255662 commit 3dc8b59
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -4358,12 +4358,12 @@ algorithm
if Expression.isArray(e1) or Expression.isArrayType(Expression.typeof(e1)) then
lst_e := Expression.getArrayOrRangeContents(e1);
for e in lst_e loop
out_lst_e1 := List.appendNoCopy(simplifyComplexFunction2(e),out_lst_e1);
out_lst_e1 := listAppend(simplifyComplexFunction2(e),out_lst_e1);
end for;
elseif Expression.isRecord(e1) then
lst_e := Expression.splitRecord(e1, Expression.typeof(e1));
for e in lst_e loop
out_lst_e1 := List.appendNoCopy(simplifyComplexFunction2(e),out_lst_e1);
out_lst_e1 := listAppend(simplifyComplexFunction2(e),out_lst_e1);
end for;
out_lst_e1 := {e1};
else
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -1720,7 +1720,7 @@ algorithm
(_, statevarindx_lst) := BackendVariable.getAllStateVarIndexFromVariables(v);
indx_lst_v := BackendVariable.getVarIndexFromVariables(iVars, v);

indx_lst_v := List.appendNoCopy(indx_lst_v, statevarindx_lst) "overestimate";
indx_lst_v := listAppend(indx_lst_v, statevarindx_lst) "overestimate";
indx_lst_e := List.map1r(indx_lst_v, arrayGet, ass1);

indx_arr := arrayCreate(equationArraySizeDAE(iSyst), 0);
Expand Down
7 changes: 1 addition & 6 deletions Compiler/BackEnd/DynamicOptimization.mo
Expand Up @@ -906,17 +906,12 @@ algorithm
BackendDAE.EQSYSTEM(orderedVars = v) := syst;
varlst := BackendVariable.varList(v);

opt_varlst := {};

conVarsList := List.select(varlst, BackendVariable.isRealOptimizeConstraintsVars);
fconVarsList := List.select(varlst, BackendVariable.isRealOptimizeFinalConstraintsVars);
objMayer := checkObjectIsSet(v,BackendDAE.optimizationMayerTermName);
objLagrange := checkObjectIsSet(v,BackendDAE.optimizationLagrangeTermName);

opt_varlst := List.appendNoCopy(opt_varlst, conVarsList);
opt_varlst := List.appendNoCopy(opt_varlst, fconVarsList);
opt_varlst := List.appendNoCopy(opt_varlst, objMayer);
opt_varlst := List.appendNoCopy(opt_varlst, objLagrange);
opt_varlst := listAppend(conVarsList, listAppend(fconVarsList, listAppend(objMayer, objLagrange)));

if not listEmpty(opt_varlst) then
newsyst := BackendDAEUtil.tryReduceEqSystem(syst, shared, opt_varlst) :: newsyst;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -303,8 +303,8 @@ algorithm
else fail();
end matchcontinue;

eqnForNewVars := List.appendNoCopy(eqnForNewVars, eqnForNewVars1);
newVarsCrefs := List.appendNoCopy(newVarsCrefs, newVarsCrefs1);
eqnForNewVars := listAppend(eqnForNewVars, eqnForNewVars1);
newVarsCrefs := listAppend(newVarsCrefs, newVarsCrefs1);

end solveWork;

Expand Down Expand Up @@ -1743,7 +1743,7 @@ algorithm
res = DAE.IFEXP(e1,lhs,rhs);
asserts = listAppend(asserts1,asserts1);
then
(res,asserts,List.appendNoCopy(eqns1,eqns), List.appendNoCopy(var1, var), depth);
(res,asserts,listAppend(eqns1,eqns), listAppend(var1, var), depth);
else fail();
end match;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/ResolveLoops.mo
Expand Up @@ -2121,7 +2121,7 @@ algorithm
true = listLength(var_lst) <= maxSize;
({},_) = List.splitOnTrue(var_lst, BackendVariable.isStateVar) "TODO: fix BackendDAEUtil.getEqnSysRhs for x and der(x)";
(syst,shared, toffset) = solveLinearSystem3(syst,shared,eqn_lst,eindex,var_lst,vindx,jac,offset);
then (syst,shared,true, List.appendNoCopy(eindex, ii), toffset);
then (syst,shared,true, listAppend(eindex, ii), toffset);
else (isyst,ishared,false, ii, offset);
end matchcontinue;
end solveLinearSystem2;
Expand Down
3 changes: 1 addition & 2 deletions Compiler/FrontEnd/ClassLoader.mo
Expand Up @@ -447,7 +447,7 @@ algorithm

po2 = List.map(differences, makeClassLoad);

po = List.appendNoCopy(po2, po1);
po = listAppend(po2, po1);
else // file not found
mofiles = List.map(System.moFiles(mp), Util.removeLast3Char) "Here .mo files in same directory as package.mo should be loaded as sub-packages";
subdirs = System.subDirectories(mp);
Expand Down Expand Up @@ -698,4 +698,3 @@ end getProgramFromStrategy;

annotation(__OpenModelica_Interface="frontend");
end ClassLoader;

4 changes: 2 additions & 2 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1547,7 +1547,7 @@ algorithm
dims := Types.getDimensions(ty);
diff := listLength(dims) - listLength(subs);
newsubs := List.fill(DAE.INDEX(DAE.ICONST(1)), diff);
subs := List.appendNoCopy(subs,newsubs);
subs := listAppend(subs,newsubs);
then
DAE.CREF_IDENT(i, ty, subs);

Expand All @@ -1556,7 +1556,7 @@ algorithm
dims := Types.getDimensions(ty);
diff := listLength(dims) - listLength(subs);
newsubs := List.fill(DAE.INDEX(DAE.ICONST(1)), diff);
subs := List.appendNoCopy(subs,newsubs);
subs := listAppend(subs,newsubs);
cr := crefArrayGetFirstCref(cr);
then
DAE.CREF_QUAL(i, ty, subs, cr);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -4965,7 +4965,7 @@ algorithm
DAE.DAE(elts2))
equation
// t1 = clock();
elts = List.appendNoCopy(elts1,elts2);
elts = listAppend(elts1,elts2);
// t2 = clock();
// ti = t2 -. t1;
// fprintln(Flags.INNER_OUTER, " joinDAEs: (" + realString(ti) + ") -> " + intString(listLength(elts1)) + " + " + intString(listLength(elts2)));
Expand Down
12 changes: 6 additions & 6 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -3115,8 +3115,8 @@ algorithm
pow_acc2 = expandFactorsWork(e2,{},noFactors,doInverseFactors);
pow_acc2 = expPowLst(pow_acc2, e3);

acc = List.appendNoCopy(pow_acc, acc);
acc = List.appendNoCopy(pow_acc2, acc);
acc = listAppend(pow_acc, acc);
acc = listAppend(pow_acc2, acc);
then acc;
// (x/y)^n = x^n*y^(-n)
case (DAE.BINARY(DAE.BINARY(e1,DAE.DIV(),e2), DAE.POW(), e3),acc,_,_)
Expand All @@ -3127,8 +3127,8 @@ algorithm
pow_acc2 = expandFactorsWork(e2,{},noFactors,doInverseFactors);
pow_acc2 = expPowLst(pow_acc2, negate(e3));

acc = List.appendNoCopy(pow_acc, acc);
acc = List.appendNoCopy(pow_acc2, acc);
acc = listAppend(pow_acc, acc);
acc = listAppend(pow_acc2, acc);
then acc;
// (x^n)^m = x^(n*m)
case (DAE.BINARY(DAE.BINARY(e1,DAE.POW(),e2), DAE.POW(), e3),acc,_,_)
Expand All @@ -3137,7 +3137,7 @@ algorithm
pow_acc = expandFactorsWork(e1,{},noFactors,doInverseFactors);
pow_acc = expPowLst(pow_acc, e);

acc = List.appendNoCopy(pow_acc, acc);
acc = listAppend(pow_acc, acc);
then acc;
// ToDo
// exp(x + y) = exp(x)*exp(y)
Expand Down Expand Up @@ -3186,7 +3186,7 @@ for elem in inAcc loop
case(DAE.UNARY(DAE.UMINUS_ARR(),_)) then expandFactorsWork(elem,{},noFactors,doInverseFactors);
else {elem};
end match;
outExpLst := List.appendNoCopy(tmpExpLst, outExpLst);
outExpLst := listAppend(tmpExpLst, outExpLst);
end for;

end expandFactorsWork2;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -2101,9 +2101,9 @@ algorithm
ErrorExt.setCheckpoint("expandableConnectorsOrder");
(cache, eqs_1, expandableEqs) = InstUtil.splitConnectEquationsExpandable(cache, env5, ih, pre, eqs_1, impl, {}, {});
// put expandable at the begining
eqs_1 = List.appendNoCopy(expandableEqs, eqs_1);
eqs_1 = listAppend(expandableEqs, eqs_1);
// put expandable at the end
eqs_1 = List.appendNoCopy(eqs_1, expandableEqs);
eqs_1 = listAppend(eqs_1, expandableEqs);
// duplicate expandable to get the union
eqs_1 = InstUtil.addExpandable(eqs_1, expandableEqs);
ErrorExt.rollBack("expandableConnectorsOrder");
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/InstSection.mo
Expand Up @@ -5434,7 +5434,7 @@ algorithm
(crefInfoList,_) = List.deleteMemberOnTrue(foundCref,crefInfoList,crefInfoListCrefsEqual);

// Now that the iterator is removed cocatenate the two lists
// crefInfoList = List.appendNoCopy(crefInfoList_tmp,crefInfoList);
// crefInfoList = listAppend(expandableEqs(crefInfoList_tmp,crefInfoList);

//check the rest
crefInfoList = collectParallelVariables(crefInfoList,restStmts);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -1476,7 +1476,7 @@ algorithm
(outE, cycles) = Graph.topologicalSort(g, isElementEqual);
// printGraph(inEnv, g, outE, cycles);
// append the elements in the cycles as they might not actually be cycles, but they depend on elements not in the list (i.e. package constants, etc)!
outE = List.appendNoCopy(outE, List.map(cycles, Util.tuple21));
outE = listAppend(outE, List.map(cycles, Util.tuple21));
checkCyclicalComponents(cycles, inEnv);
then
outE;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1919,7 +1919,7 @@ public function liftTypeWithDims "
algorithm
outType := match inType
local
list<DAE.Dimension> dims;
list<DAE.Dimension> dims, dims_;
DAE.Type ty;
DAE.TypeSource src;

Expand All @@ -1930,8 +1930,8 @@ algorithm

case DAE.T_ARRAY(ty, dims, src)
algorithm
dims := List.appendNoCopy(dims, inDims);
then DAE.T_ARRAY(ty, dims, src);
dims_ := listAppend(dims, inDims);
then if referenceEq(dims,dims_) then inType else DAE.T_ARRAY(ty, dims_, src);

else
DAE.T_ARRAY(inType, inDims, DAE.emptyTypeSource);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -1997,7 +1997,7 @@ algorithm
source = ElementSource.addSymbolicTransformationSolve(true, source, cr, e1, e2, exp_, asserts);
(eqSystlst, uniqueEqIndex) = List.mapFold(solveEqns, makeSolved_SES_SIMPLE_ASSIGN, iuniqueEqIndex);
(resEqs, uniqueEqIndex) = addAssertEqn(asserts, {SimCode.SES_SIMPLE_ASSIGN(uniqueEqIndex, cr, exp_, source)}, uniqueEqIndex+1);
eqSystlst = List.appendNoCopy(eqSystlst,resEqs);
eqSystlst = listAppend(eqSystlst,resEqs);
tempvars = createTempVarsforCrefs(List.map(solveCr, Expression.crefExp),itempvars);
then
(eqSystlst, uniqueEqIndex,tempvars);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Util/Graph.mo
Expand Up @@ -133,7 +133,7 @@ algorithm
match(inStartNodes, inRestNodes, inAccumNodes, inEqualFunc)
local
NodeType node1;
list<tuple<NodeType, list<NodeType>>> rest_start, rest_rest, new_start;
list<tuple<NodeType, list<NodeType>>> rest_start, rest_start_, rest_rest, new_start;
list<NodeType> result;

// No more nodes to sort, reverse the accumulated nodes (because of
Expand Down Expand Up @@ -161,10 +161,10 @@ algorithm
(rest_rest, new_start) =
List.splitOnTrue(rest_rest, hasOutgoingEdges);
// Append those nodes to the list of start nodes.
rest_start = List.appendNoCopy(rest_start, new_start);
rest_start_ = listAppend(rest_start, new_start);
// Add the first node to the list of sorted nodes and continue with the
// rest of the nodes.
(result, rest_rest) = topologicalSort2(rest_start, rest_rest,
(result, rest_rest) = topologicalSort2(rest_start_, rest_rest,
node1 :: inAccumNodes, inEqualFunc);
then
(result, rest_rest);
Expand Down
16 changes: 0 additions & 16 deletions Compiler/Util/List.mo
Expand Up @@ -379,22 +379,6 @@ algorithm
end for;
end consN;

public function appendNoCopy<T>
"This function handles special cases such as empty lists so it does not copy
if any of the arguments are empty lists.

TODO: RML-specific. Not needed in bootstrapped OMC"
input list<T> inList1;
input list<T> inList2;
output list<T> outList;
algorithm
outList := match(inList1, inList2)
case ({}, _) then inList2;
case (_, {}) then inList1;
else listAppend(inList1, inList2);
end match;
end appendNoCopy;

public function append_reverse<T>
"Appends the elements from list1 in reverse order to list2."
input list<T> inList1;
Expand Down

0 comments on commit 3dc8b59

Please sign in to comment.