perf: Optimizing next and previous properties
This commit is contained in:
+2
-4
@@ -426,8 +426,7 @@ class Selector(SelectorsGeneration):
|
||||
def next(self) -> Optional["Selector"]:
|
||||
"""Returns the next element of the current element in the children of the parent or ``None`` otherwise."""
|
||||
next_element = self._root.getnext()
|
||||
if next_element is not None:
|
||||
while isinstance(next_element, html_forbidden):
|
||||
while next_element is not None and isinstance(next_element, html_forbidden):
|
||||
# Ignore HTML comments and unwanted types
|
||||
next_element = next_element.getnext()
|
||||
|
||||
@@ -437,8 +436,7 @@ class Selector(SelectorsGeneration):
|
||||
def previous(self) -> Optional["Selector"]:
|
||||
"""Returns the previous element of the current element in the children of the parent or ``None`` otherwise."""
|
||||
prev_element = self._root.getprevious()
|
||||
if prev_element is not None:
|
||||
while isinstance(prev_element, html_forbidden):
|
||||
while prev_element is not None and isinstance(prev_element, html_forbidden):
|
||||
# Ignore HTML comments and unwanted types
|
||||
prev_element = prev_element.getprevious()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user