diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2022-03-18 10:37:32 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2022-03-18 10:37:32 +0100 |
commit | 5f94e88d349ee34f858e1674889eb1ba76c3543d (patch) | |
tree | 83c47623131bc2b62c7bb671f0929205333f25ba /container-search | |
parent | dda5975159f6ea99b1d79aba6b80fcd56271d82f (diff) |
Walk down tree trunk, rather than to all leaves, to check for cycles
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java b/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java index 9ae1a03b38f..f48dc9a8630 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/CompositeItem.java @@ -42,13 +42,9 @@ public abstract class CompositeItem extends Item { } public void ensureNotInSubtree(CompositeItem item) { - for (Iterator<Item> i = item.getItemIterator(); i.hasNext();) { - Item possibleCycle = i.next(); - - if (this == possibleCycle) { + for (Item i = this; i != null; i = i.getParent()) { + if (i == item) { throw new IllegalArgumentException("Cannot add " + item + " to " + this + " as it would create a cycle"); - } else if (possibleCycle instanceof CompositeItem) { - ensureNotInSubtree((CompositeItem) possibleCycle); } } } |