From c3325a8966a71550c9fe319b2d366ff7f89fff0f Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 22 Oct 2014 14:24:33 -0400 Subject: [PATCH] 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. --- config/src/main/java/com/typesafe/config/impl/MemoKey.java | 7 +------ .../main/java/com/typesafe/config/impl/ResolveContext.java | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/impl/MemoKey.java b/config/src/main/java/com/typesafe/config/impl/MemoKey.java index d948aed0..cd843dad 100644 --- a/config/src/main/java/com/typesafe/config/impl/MemoKey.java +++ b/config/src/main/java/com/typesafe/config/impl/MemoKey.java @@ -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) diff --git a/config/src/main/java/com/typesafe/config/impl/ResolveContext.java b/config/src/main/java/com/typesafe/config/impl/ResolveContext.java index 076d07fe..cf669912 100644 --- a/config/src/main/java/com/typesafe/config/impl/ResolveContext.java +++ b/config/src/main/java/com/typesafe/config/impl/ResolveContext.java @@ -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); }