Skip to content

Commit 9caa358

Browse files
committed
Optimize VerifyModel.checkDiscreteReal
- Don't strip subscripts from and reallocate every single variable when we only need to look up discrete ones. - Use hash and equality functions that ignores subscripts to avoid having to strip subscripts at all.
1 parent bf17187 commit 9caa358

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

OMCompiler/Compiler/NFFrontEnd/NFVerifyModel.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ protected
351351
list<Variable> illegal_discrete_vars = {};
352352
String err_str = "";
353353
algorithm
354-
discrete_reals := UnorderedSet.new(ComponentRef.hash, ComponentRef.isEqual);
354+
discrete_reals := UnorderedSet.new(ComponentRef.hashStrip, ComponentRef.isEqualStrip);
355355

356356
// collect all lhs crefs that are discrete and real from equations
357357
for eqn in flatModel.equations loop
@@ -369,7 +369,6 @@ protected
369369
for variable in flatModel.variables loop
370370
// check variability and not type for discrete variables
371371
// remove all subscripts to handle arrays
372-
variable.name := ComponentRef.stripSubscriptsAll(variable.name);
373372
if Variable.variability(variable) == Variability.DISCRETE and Type.isReal(Type.arrayElementType(variable.ty)) and
374373
not UnorderedSet.contains(variable.name, discrete_reals) then
375374
illegal_discrete_vars := variable :: illegal_discrete_vars;
@@ -379,7 +378,8 @@ protected
379378
// report error if there are any
380379
if not listEmpty(illegal_discrete_vars) then
381380
for var in illegal_discrete_vars loop
382-
Error.addSourceMessage(Error.DISCRETE_REAL_UNDEFINED, {ComponentRef.toString(var.name)}, var.info);
381+
Error.addSourceMessage(Error.DISCRETE_REAL_UNDEFINED,
382+
{ComponentRef.toString(ComponentRef.stripSubscriptsAll(var.name))}, var.info);
383383
end for;
384384
fail();
385385
end if;
@@ -545,7 +545,7 @@ protected
545545
guard(Type.isReal(Type.arrayElementType(ty)))
546546
algorithm
547547
// remove all subscripts to handle arrays
548-
UnorderedSet.add(ComponentRef.stripSubscriptsAll(cref), discreteReals);
548+
UnorderedSet.add(cref, discreteReals);
549549
then
550550
();
551551

@@ -577,12 +577,12 @@ protected
577577
list<InstNode> inputs;
578578
algorithm
579579
// remove all subscripts to handle arrays
580-
UnorderedSet.add(ComponentRef.stripSubscriptsAll(cref), discreteReals);
580+
UnorderedSet.add(cref, discreteReals);
581581
// also add all record elements
582582
(inputs, _, _) := Record.collectRecordParams(cls);
583583
for node in inputs loop
584584
element := ComponentRef.prefixCref(node, InstNode.getType(node), {}, cref);
585-
UnorderedSet.add(ComponentRef.stripSubscriptsAll(element), discreteReals);
585+
UnorderedSet.add(element, discreteReals);
586586
end for;
587587
end checkDiscreteRealRecord;
588588

0 commit comments

Comments
 (0)