Skip to content

Commit

Permalink
some small list optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel authored and OpenModelica-Hudson committed Oct 5, 2017
1 parent f85f44f commit d3f9ab1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -9188,7 +9188,7 @@ algorithm
eqs := arrayGet(mT, i);
var := BackendVariable.getVarAt(varsArray, i);
info := var.source.info;
if listLength(eqs) == 0 then
if listEmpty(eqs) then
Error.addSourceMessage(Error.VAR_NO_REMAINING_EQN, {
ComponentReference.printComponentRefStr(var.varName),
stringAppendList(list("\n Equation " + String(eq) + ": " + BackendDump.equationString(BackendEquation.get(eqsArray, eq)) + ", which needs to solve for " + stringDelimitList(list(ComponentReference.printComponentRefStr(Util.tuple21(tpl)) for tpl in arrayGet(solvedEqs, eq)), ", ") for eq in arrayGet(mTOrig, i)))
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Matching.mo
Expand Up @@ -249,7 +249,7 @@ protected
algorithm
for i in 1:nEqns loop
vars := m[i];
while not success and (listLength(vars) > 0) loop
while not success and not listEmpty(vars) loop
j::vars := vars;
// negative entries in adjacence matrix belong to states!!!
if (j>0 and ass1[j] <= 0) then
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/SynchronousFeatures.mo
Expand Up @@ -93,7 +93,7 @@ protected
algorithm
(clockedSysts, contSysts) := List.splitOnTrue(inDAE.eqs, BackendDAEUtil.isClockedSyst);

if listLength(clockedSysts) > 0 then
if not listEmpty(clockedSysts) then
shared := inDAE.shared;

(clockedSysts, shared) := treatClockedStates(clockedSysts, shared);
Expand Down Expand Up @@ -124,7 +124,7 @@ algorithm
(clockedSysts, systs) := List.splitOnTrue(inDAE.eqs, BackendDAEUtil.isClockedSyst);
shared := inDAE.shared;

if listLength(systs) > 0 then
if not listEmpty(systs) then
BackendDAE.DAE({syst}, shared) := BackendDAEOptimize.collapseIndependentBlocks(BackendDAE.DAE(systs, shared));
(systs, clockedSysts1, unpartRemEqs) := baseClockPartitioning(syst, shared);
assert(listLength(clockedSysts1) == 0, "Get clocked system in SynchronousFeatures.addContVarsEqs");
Expand Down
7 changes: 5 additions & 2 deletions Compiler/BackEnd/Tearing.mo
Expand Up @@ -377,8 +377,10 @@ protected function getUserTearingSet
output list<Integer> userResidualsThisComponent={};
protected
Integer i=1, start, end_;
Integer len;
algorithm
while i < listLength(userTVars) loop
len := listLength(userTVars);
while i < len loop
if intEq(listGet(userTVars,i),strongComponentIndex) then
start := i+2;
end_ := i + 1 + listGet(userTVars, i+1);
Expand All @@ -394,7 +396,8 @@ algorithm
end while;
if not listEmpty(userTvarsThisComponent) then
i := 1;
while i < listLength(userResiduals) loop
len := listLength(userResiduals);
while i < len loop
if intEq(listGet(userResiduals,i),strongComponentIndex) then
start := i+2;
end_ := i + 1 + listGet(userResiduals, i+1);
Expand Down
9 changes: 2 additions & 7 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -427,24 +427,19 @@ algorithm
Type at;
DAE.Dimensions ad;
DAE.Dimension dim;
Integer ll;
list<DAE.Var> vars;
ClassInf.State CIS;
DAE.EqualityConstraint ec;

// convert just the array!
case DAE.T_ARRAY(at,dim::ad)
equation
ll = listLength(ad);
true = (ll == 0);
case DAE.T_ARRAY(at,{dim})
equation
ty = expTypetoTypesType(at);
tty = DAE.T_ARRAY(ty,{dim});
then
tty;
case DAE.T_ARRAY(at,dim::ad)
equation
ll = listLength(ad);
true = (ll > 0);
ty = expTypetoTypesType(DAE.T_ARRAY(at,ad));
tty = DAE.T_ARRAY(ty,{dim});
then
Expand Down
2 changes: 1 addition & 1 deletion Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -890,7 +890,7 @@ protected function setJacobianVars "author: unknown
protected
SimCodeVar.SimVars vars;
algorithm
if listLength(iJacobianVars) > 0 then
if not listEmpty(iJacobianVars) then
vars := oModelInfo.vars;
vars.jacobianVars := iJacobianVars;
oModelInfo.vars := vars;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/Util.mo
Expand Up @@ -496,7 +496,7 @@ protected
algorithm
lst:=stringSplitAtChar(inString,delim);
lst2:=List.map(lst, stringInt);
if(intGt(listLength(lst2), 0)) then
if not listEmpty(lst2) then
i := List.fold(lst2,intMul,1);
else
i := 0;
Expand Down

0 comments on commit d3f9ab1

Please sign in to comment.