From 5aca61bd68861a7c03cb1410479a3128de3f492c Mon Sep 17 00:00:00 2001 From: Tobias Reiher Date: Mon, 19 Oct 2020 10:36:56 +0200 Subject: [PATCH] Improve performance of specification parser Ref. #95, #343, #466 --- rflx/specification/parser.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rflx/specification/parser.py b/rflx/specification/parser.py index ed8c86fa9..70efefa73 100644 --- a/rflx/specification/parser.py +++ b/rflx/specification/parser.py @@ -332,9 +332,13 @@ def create_message_structure(components: Sequence[Component], error: RecordFluxE target_node = Field(name) if name else FINAL structure.append(Link(source_node, target_node)) - if component.first != expr.UNDEFINED: - for l in structure: - if l.target.identifier == component.name: + if ( + component.first != expr.UNDEFINED + or component.length != expr.UNDEFINED + or component.condition != expr.TRUE + ): + for l in (l for l in structure if l.target.identifier == component.name): + if component.first != expr.UNDEFINED: if l.first == expr.UNDEFINED: l.first = component.first else: @@ -352,9 +356,7 @@ def create_message_structure(components: Sequence[Component], error: RecordFluxE l.first.location, ) - if component.length != expr.UNDEFINED: - for l in structure: - if l.target.identifier == component.name: + if component.length != expr.UNDEFINED: if l.length == expr.UNDEFINED: l.length = component.length else: @@ -372,9 +374,7 @@ def create_message_structure(components: Sequence[Component], error: RecordFluxE l.length.location, ) - if component.condition != expr.TRUE: - for l in structure: - if l.target.identifier == component.name: + if component.condition != expr.TRUE: l.condition = ( expr.And(component.condition, l.condition, location=l.condition.location) if l.condition != expr.TRUE