Optimize bytecode size of buildDeclared() by off-loading actual
work to loadDeclared(). Improves inlining and improves tracing
visibility -- which shows that the cache has about 90% cach hit
rate.
Change-Id: If09d417ab5257bf6651b94da2506695a6ced0104
JIRA: YANGTOOLS-652
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
@Override
public final D buildDeclared() {
- final D existing = declaredInstance;
- if (existing != null) {
- return existing;
- }
+ final D existing;
+ return (existing = declaredInstance) != null ? existing : loadDeclared();
+ }
+
+ private @NonNull D loadDeclared() {
final ModelProcessingPhase phase = getCompletedPhase();
checkState(phase == ModelProcessingPhase.FULL_DECLARATION || phase == ModelProcessingPhase.EFFECTIVE_MODEL,
"Cannot build declared instance after phase %s", phase);