mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 23:01:05 +08:00
Remove "root" from MemoKey
This was just wrong in the new setup; we change the root constantly. The MemoKey should be per-conceptual-resolve which is per-ResolveContext, not per-root. This commit fixes the tests in which we failed to memoize and thus got different results for the same ConfigReference at different times in the resolution process. But it breaks ConfigSubstitutionTest.avoidDelayedMergeObjectResolveProblem5.
This commit is contained in:
parent
1a65f861b2
commit
c3325a8966
@ -2,20 +2,17 @@ package com.typesafe.config.impl;
|
||||
|
||||
/** The key used to memoize already-traversed nodes when resolving substitutions */
|
||||
final class MemoKey {
|
||||
MemoKey(AbstractConfigValue root, AbstractConfigValue value, Path restrictToChildOrNull) {
|
||||
this.root = root;
|
||||
MemoKey(AbstractConfigValue value, Path restrictToChildOrNull) {
|
||||
this.value = value;
|
||||
this.restrictToChildOrNull = restrictToChildOrNull;
|
||||
}
|
||||
|
||||
final private AbstractConfigValue root;
|
||||
final private AbstractConfigValue value;
|
||||
final private Path restrictToChildOrNull;
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
int h = System.identityHashCode(value);
|
||||
h = h + 41 * (41 + root.hashCode());
|
||||
if (restrictToChildOrNull != null) {
|
||||
return h + 41 * (41 + restrictToChildOrNull.hashCode());
|
||||
} else {
|
||||
@ -29,8 +26,6 @@ final class MemoKey {
|
||||
MemoKey o = (MemoKey) other;
|
||||
if (o.value != this.value)
|
||||
return false;
|
||||
else if (o.root != this.root)
|
||||
return false;
|
||||
else if (o.restrictToChildOrNull == this.restrictToChildOrNull)
|
||||
return true;
|
||||
else if (o.restrictToChildOrNull == null || this.restrictToChildOrNull == null)
|
||||
|
@ -146,7 +146,7 @@ final class ResolveContext {
|
||||
throws NotPossibleToResolve {
|
||||
// a fully-resolved (no restrictToChild) object can satisfy a
|
||||
// request for a restricted object, so always check that first.
|
||||
final MemoKey fullKey = new MemoKey(source.root, original, null);
|
||||
final MemoKey fullKey = new MemoKey(original, null);
|
||||
MemoKey restrictedKey = null;
|
||||
|
||||
AbstractConfigValue cached = memos.get(fullKey);
|
||||
@ -155,7 +155,7 @@ final class ResolveContext {
|
||||
// compute the restrictToChild object so use a more limited
|
||||
// memo key
|
||||
if (cached == null && isRestrictedToChild()) {
|
||||
restrictedKey = new MemoKey(source.root, original, restrictToChild());
|
||||
restrictedKey = new MemoKey(original, restrictToChild());
|
||||
cached = memos.get(restrictedKey);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user