Speed up PeerSpecificParserConstraintImpl 68/78568/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Dec 2018 10:34:19 +0000 (11:34 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Mon, 10 Dec 2018 06:53:57 +0000 (06:53 +0000)
commit0e112b4e95a73ca6bc218af0f8a03696886f46c9
treeca3d2775efe618a68f6b7d72d9db9f411271406b
parent8bd1e60098e90192a5783f151c2157722eca589a
Speed up PeerSpecificParserConstraintImpl

This improves design by taking advantage of ClassToInstanceMap,
which provides a type-safe getInstance() method. Furthermore we
recognize that the this class is used mostly for lookups of a few
classes, we use an ImmutableClassToInstanceMap updated concurrently
via a compare-and-set.

This yields significantly faster lookups for the common cases, where
the map is empty or has a single entry. In other cases the speed up
is still there, although not as pronounced.

Change-Id: I4da36e592e88cf22d5ad1654f126eec81660c98c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit a86726e5e52d64a13882051e965f0498910ce941)
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/PeerSpecificParserConstraintImpl.java