From 78be89abde691c066fd55a1ca24254447e21cfe6 Mon Sep 17 00:00:00 2001 From: Jonathan Hedley Date: Fri, 22 Dec 2023 14:49:23 +1100 Subject: [PATCH] Move iter into Has class #2088 --- src/main/java/org/jsoup/select/StructuralEvaluator.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jsoup/select/StructuralEvaluator.java b/src/main/java/org/jsoup/select/StructuralEvaluator.java index 8808439a80..ce5051fb85 100644 --- a/src/main/java/org/jsoup/select/StructuralEvaluator.java +++ b/src/main/java/org/jsoup/select/StructuralEvaluator.java @@ -58,11 +58,10 @@ public boolean matches(Element root, Element element) { } } - final ThreadLocal> threadHasIter = - ThreadLocal.withInitial(() -> new NodeIterator<>(new Element("html"), Element.class)); - // the element here is just a placeholder so this can be final - gets set in restart() - static class Has extends StructuralEvaluator { + static final ThreadLocal> ThreadElementIter = + ThreadLocal.withInitial(() -> new NodeIterator<>(new Element("html"), Element.class)); + // the element here is just a placeholder so this can be final - gets set in restart() public Has(Evaluator evaluator) { super(evaluator); @@ -70,7 +69,7 @@ public Has(Evaluator evaluator) { @Override public boolean matches(Element root, Element element) { // for :has, we only want to match children (or below), not the input element. And we want to minimize GCs - NodeIterator it = threadHasIter.get(); + NodeIterator it = ThreadElementIter.get(); it.restart(element); while (it.hasNext()) {