From e6dd23c2db4b883052f8d026c3f4c2074e2786bc Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 8 Sep 2014 18:32:39 +0200 Subject: [PATCH] BUG-650: speed up ResolveDataChangeState.needsProcessing() Checking for empty subBuilders allows us to reuse the parent's collection. For simple cases with no listeners whis speeds up needsProcessing() by completely reusing the emptyList and for non-trivial cases it just omits object instantiation. Change-Id: Ib3089bca2ec4f7e1ef826bf4192b8154ff154702 Signed-off-by: Robert Varga --- .../dom/store/impl/ResolveDataChangeState.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java index d3c5a7cb70..ea95030de3 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeState.java @@ -103,8 +103,19 @@ final class ResolveDataChangeState { * @return State handle */ public ResolveDataChangeState child(final PathArgument childId) { - return new ResolveDataChangeState(nodeId.node(childId), - Iterables.concat(inheritedSub, subBuilders.values()), + /* + * We instantiate a concatenation only when needed, otherwise + * we reuse the collection. This speeds up Iterables.isEmpty() + * in needsProcessing(). + */ + final Iterable sb; + if (subBuilders.isEmpty()) { + sb = inheritedSub; + } else { + sb = Iterables.concat(inheritedSub, subBuilders.values()); + } + + return new ResolveDataChangeState(nodeId.node(childId), sb, oneBuilders.values(), getListenerChildrenWildcarded(nodes, childId)); } -- 2.36.6