From 7caa6ccc10a74b60b26abd1178636f31a1b0a4b1 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 14 Feb 2020 10:52:07 +0100 Subject: [PATCH] Split up tryToCompletePhase() This method is incredibly hot, split it up so that it is easier to optimize as well as profile. JIRA: YANGTOOLS-652 Change-Id: I3f87a00061c5f45f80364de3ba1a249beaa25b7f Signed-off-by: Robert Varga --- .../stmt/reactor/StatementContextBase.java | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java index 12e812e24f..3e39fd345f 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java @@ -522,37 +522,23 @@ public abstract class StatementContextBase, E } /** - * tries to execute current {@link ModelProcessingPhase} of source parsing. + * Try to execute current {@link ModelProcessingPhase} of source parsing. * - * @param phase - * to be executed (completed) + * @param phase to be executed (completed) * @return if phase was successfully completed - * @throws SourceException - * when an error occurred in source parsing + * @throws SourceException when an error occurred in source parsing */ - boolean tryToCompletePhase(final ModelProcessingPhase phase) { - - boolean finished = true; - final Collection openMutations = phaseMutation.get(phase); - if (!openMutations.isEmpty()) { - final Iterator it = openMutations.iterator(); - while (it.hasNext()) { - final ContextMutation current = it.next(); - if (current.isFinished()) { - it.remove(); - } else { - finished = false; - } - } - - if (openMutations.isEmpty()) { - phaseMutation.removeAll(phase); - if (phaseMutation.isEmpty()) { - phaseMutation = ImmutableMultimap.of(); - } - } + final boolean tryToCompletePhase(final ModelProcessingPhase phase) { + final boolean finished = phaseMutation.isEmpty() ? true : runMutations(phase); + if (completeChildren(phase) && finished) { + onPhaseCompleted(phase); + return true; } + return false; + } + private boolean completeChildren(final ModelProcessingPhase phase) { + boolean finished = true; for (final StatementContextBase child : mutableDeclaredSubstatements()) { finished &= child.tryToCompletePhase(phase); } @@ -561,12 +547,33 @@ public abstract class StatementContextBase, E finished &= ((StatementContextBase) child).tryToCompletePhase(phase); } } + return finished; + } - if (finished) { - onPhaseCompleted(phase); - return true; + private boolean runMutations(final ModelProcessingPhase phase) { + final Collection openMutations = phaseMutation.get(phase); + return openMutations.isEmpty() ? true : runMutations(phase, openMutations); + } + + private boolean runMutations(final ModelProcessingPhase phase, final Collection openMutations) { + boolean finished = true; + final Iterator it = openMutations.iterator(); + while (it.hasNext()) { + final ContextMutation current = it.next(); + if (current.isFinished()) { + it.remove(); + } else { + finished = false; + } } - return false; + + if (openMutations.isEmpty()) { + phaseMutation.removeAll(phase); + if (phaseMutation.isEmpty()) { + phaseMutation = ImmutableMultimap.of(); + } + } + return finished; } /** -- 2.36.6