Skip to content

Commit

Permalink
Tidied up loops
Browse files Browse the repository at this point in the history
While -> for
  • Loading branch information
jhy committed Jul 4, 2024
1 parent 6de7cfc commit c393413
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main/java/org/jsoup/select/StructuralEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ public boolean matches(Element root, Element element) {
if (root == element)
return false;

Element parent = element.parent();
while (parent != null) {
for (Element parent = element.parent(); parent != null; parent = parent.parent()) {
if (memoMatches(root, parent))
return true;
if (parent == root)
break;
parent = parent.parent();
}
return false;
}
Expand Down Expand Up @@ -230,11 +228,9 @@ public PreviousSibling(Evaluator evaluator) {
public boolean matches(Element root, Element element) {
if (root == element) return false;

Element sibling = element.firstElementSibling();
while (sibling != null) {
if (sibling == element) break;
if (memoMatches(root, sibling)) return true;
sibling = sibling.nextElementSibling();
for (Element sib = element.firstElementSibling(); sib != null; sib = sib.nextElementSibling()) {
if (sib == element) break;
if (memoMatches(root, sib)) return true;
}

return false;
Expand Down

0 comments on commit c393413

Please sign in to comment.