Skip to content

Commit

Permalink
replaced "if listLength(lst)>0 then" with "if not listEmpty(lst) then"
Browse files Browse the repository at this point in the history
to reduce run time (O(n) -> O(1))


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25585 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Apr 16, 2015
1 parent 0db2434 commit 0efc38a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -429,7 +429,7 @@ public function iterationVarsinRelations
output list<Integer> indexes;
algorithm
(_, (_,(indexes, _))) := traverseExpsOfEquationList(inEquationLst, Expression.traverseSubexpressionsHelper, (traversingRelationsforIterationVars, ({}, inVars)));
mixedSystem := if listLength(indexes)>0 then true else false;
mixedSystem := not listEmpty(indexes);
end iterationVarsinRelations;

protected function traversingRelationsforIterationVars
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -1712,7 +1712,7 @@ algorithm
(stmts1,true) = replaceStatementLst(stmts,repl,inFuncTypeExpExpToBooleanOption,{},false);
alg = DAE.ALGORITHM_STMTS(stmts1);
// if all statements are removed, remove the whole algorithm
eqns = if listLength(stmts1)>0 then BackendDAE.ALGORITHM(size,alg,source,crefExpand,eqAttr)::inAcc else inAcc;
eqns = if not listEmpty(stmts1) then BackendDAE.ALGORITHM(size,alg,source,crefExpand,eqAttr)::inAcc else inAcc;
then
(eqns,true);

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/DynamicOptimization.mo
Expand Up @@ -120,7 +120,7 @@ protected
list<BackendDAE.Var> tG = findTimeGrid(varlst);
list<Integer> ind;
algorithm
if listLength(tG) > 0 then
if not listEmpty(tG) then
ind := BackendVariable.getVarIndexFromVars(tG, ov);
for i in ind loop
ov := BackendVariable.setVarKindForVar(i, BackendDAE.OPT_TGRID(), ov);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/RemoveSimpleEquations.mo
Expand Up @@ -4996,7 +4996,7 @@ algorithm
end if;
(HTStartExpToInt,HTNominalExpToInt) = getThisAttributes(cr1,cr_eq_lst,inAliasVars,HTStartExpToInt,HTNominalExpToInt);
tplExpIndList = BaseHashTable.hashTableList(HTStartExpToInt);
if listLength(tplExpIndList)>0 then
if not listEmpty(tplExpIndList) then
e = getDominantAttributeValue(tplExpIndList);
v = BackendVariable.setVarStartValue(v,e);
if Flags.isSet(Flags.DEBUG_ALIAS) then
Expand All @@ -5005,7 +5005,7 @@ algorithm
end if;
end if;
tplExpIndList = BaseHashTable.hashTableList(HTNominalExpToInt);
if listLength(tplExpIndList)>0 then
if not listEmpty(tplExpIndList) then
e = getDominantAttributeValue(tplExpIndList);
v = BackendVariable.setVarNominalValue(v,e);
if Flags.isSet(Flags.DEBUG_ALIAS) then
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/StateMachineFeatures.mo
Expand Up @@ -215,7 +215,7 @@ algorithm
// Identify modes in the system
modes := identifyModes(shared);
names := List.map(BaseHashTable.hashTableKeyList(modes), ComponentReference.crefLastIdent);
if (listLength(names) > 0) then
if (not listEmpty(names)) then
if DEBUG_SMDUMP then
print("***** SMF-stateMachineElab States: ***** \n" + stringDelimitList(names, ",") + "\n");
print("***** SMF-stateMachineElab ModeTable: ***** \n");
Expand Down Expand Up @@ -888,7 +888,7 @@ algorithm
systOut := List.fold(vars, BackendVariable.addVarDAE, systIn);
systOut := BackendEquation.equationsAddDAE(wrappedEqs, systOut);
sharedOut := List.fold(knowns, BackendVariable.addNewKnVarDAE, sharedIn);
if (listLength(wrappedEqs) > 0) then
if (not listEmpty(wrappedEqs)) then
sharedOut := wrapAddTimeEventHack({timeEvent}, sharedOut);
end if;
end wrapHack;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/Tearing.mo
Expand Up @@ -2008,7 +2008,7 @@ algorithm
// hier (sehr kleine Listen, wird einmal am Anfang gemacht und immer wenn neue unsolvables dazugekommen sind,
// max so oft wie es tvars gibt)
tVar_never = List.intersectionOnTrue(tSel_never,tvars,intEq);
if listLength(tVar_never)<>0 then
if not listEmpty(tVar_never) then
Error.addCompilerWarning("There are tearing variables with annotation attribute 'tearingSelect = never'. Use +d=tearingdump and +d=tearingdumpV for more information.");
end if;
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
Expand Down Expand Up @@ -2622,7 +2622,7 @@ algorithm
counts2 := listReverse(counts2);
// 12. Calculate the sum of number of impossible assignments and causalizable equations for each variable and save them in points2
points2 := List.threadMap(counts1,counts2,intAdd);
points2 := if listLength(points2)==0 then {0} else points2;
points2 := if listEmpty(points2) then {0} else points2;
if Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
print("\nPoints: "+ stringDelimitList(List.map(points2,intString),",")+"\n(Sum of impossible assignments and causalizable equations)\n");
end if;
Expand Down

0 comments on commit 0efc38a

Please sign in to comment.