Skip to content

Commit b95d7ce

Browse files
committed
some cleanup on top
1 parent d04f511 commit b95d7ce

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.ArrayList;
77
import java.util.Collection;
88
import java.util.Collections;
9-
import java.util.HashMap;
9+
import java.util.LinkedHashMap;
1010
import java.util.List;
1111
import java.util.Map;
1212

@@ -85,10 +85,8 @@ static ResolveResult<? extends AbstractConfigValue> resolveSubstitutions(Replace
8585
AbstractConfigValue merged = null;
8686
for (AbstractConfigValue end : stack) {
8787
// Per the HOCON spec, a substitution hidden by a value that
88-
// cannot be merged with it is never evaluated. Once the
89-
// accumulated merged value ignores fallbacks, nothing below it
90-
// in the stack can contribute, so skip it to avoid evaluating
91-
// substitutions that cannot affect the result.
88+
// cannot be merged with it is never evaluated. If merged already
89+
// ignores fallbacks, nothing below can contribute, so stop.
9290
if (merged != null && merged.ignoresFallbacks()) {
9391
if (ConfigImpl.traceSubstitutionsEnabled())
9492
ConfigImpl.trace(newContext.depth(),
@@ -135,17 +133,11 @@ else if (end instanceof Unmergeable) {
135133

136134
sourceForEnd = source.pushParent(replaceable);
137135

138-
// Per the HOCON spec, a substitution hidden by a value that
139-
// cannot be merged with it is never evaluated. When merging
140-
// objects field-by-field the merged object may already contain,
141-
// at some keys, values that ignore fallbacks (e.g. a resolved
142-
// non-object shadowing a substitution below). Any substitution
143-
// at those same keys in a lower-priority object on the stack
144-
// would be discarded by the subsequent merge anyway, so we
145-
// prune those keys before resolving to avoid evaluating
146-
// substitutions that cannot contribute to the result.
147-
if (merged instanceof AbstractConfigObject && end instanceof AbstractConfigObject
148-
&& !(end instanceof Unmergeable)) {
136+
// Same spec rule as the short-circuit above, applied per-key:
137+
// keys in the lower-priority 'end' object that are already
138+
// shadowed in 'merged' by a value ignoring fallbacks would be
139+
// discarded by the subsequent merge, so don't resolve them.
140+
if (merged instanceof AbstractConfigObject && end instanceof AbstractConfigObject) {
149141
AbstractConfigObject prunedEnd = pruneShadowedKeys(
150142
(AbstractConfigObject) end, (AbstractConfigObject) merged);
151143
if (prunedEnd == null) {
@@ -198,7 +190,7 @@ private static AbstractConfigObject pruneShadowedKeys(AbstractConfigObject end,
198190
if (!(end instanceof SimpleConfigObject))
199191
return end;
200192
SimpleConfigObject simple = (SimpleConfigObject) end;
201-
Map<String, AbstractConfigValue> kept = new HashMap<String, AbstractConfigValue>();
193+
Map<String, AbstractConfigValue> kept = new LinkedHashMap<String, AbstractConfigValue>();
202194
boolean pruned = false;
203195
for (String key : simple.keySet()) {
204196
AbstractConfigValue mergedValue;

0 commit comments

Comments
 (0)