BUG-5222: Optimize SubstatementValidator 16/49816/8
authorRobert Varga <rovarga@cisco.com>
Mon, 26 Dec 2016 17:00:35 +0000 (18:00 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 10 Jan 2017 20:53:43 +0000 (20:53 +0000)
commit5f7479eeea883485aeb64db74787f26d4f3e7870
treeb680e16b4a3f6497a35a708377874ed3c776a4cc
parentf8f8071625fd610f203aec17232048e8cc96b84d
BUG-5222: Optimize SubstatementValidator

SubstatementValidator's execution was quite inefficient in its
operation.

During the initial phase of counting substatements by their type
it performed multiple lookups coupled with boxing. Fix this by
introducing a simple counter class and using computeIfAbsent(),
which results in a single lookup, no replacement and only primitive
increment.

During the cardinality checking, we looked up the cardinality
three times. Fix this by performing a single lookup and store
the result in local variable for further use.

For catching missing mandatory statements we take an alternative
approach, where we pre-compute the map of mandatory statements
at construction time and instantiate a HashMap before iterating
over the statements. Everytime we hit a mandatory statement
we remove the corresponding entry, which means that if everything
is okay, the map will be empty.

Finally we remove SpecialCase and its related check, is it is
not used anywhere since BUG-6173 was addressed.

Change-Id: I38582e463a2e027aef7573baeec4923fba254018
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/SubstatementValidator.java