Skip to content

Commit

Permalink
Move iter into Has class
Browse files Browse the repository at this point in the history
  • Loading branch information
jhy committed Dec 22, 2023
1 parent 374ded2 commit 78be89a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/jsoup/select/StructuralEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ public boolean matches(Element root, Element element) {
}
}

final ThreadLocal<NodeIterator<Element>> 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<NodeIterator<Element>> 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);
}

@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<Element> it = threadHasIter.get();
NodeIterator<Element> it = ThreadElementIter.get();

it.restart(element);
while (it.hasNext()) {
Expand Down

0 comments on commit 78be89a

Please sign in to comment.