perf: speeding up find_by_text and find_by_regex by 3%
This commit is contained in:
+5
-8
@@ -50,6 +50,9 @@ _whitelisted = {
|
|||||||
}
|
}
|
||||||
# Pre-compiled selectors for efficiency
|
# Pre-compiled selectors for efficiency
|
||||||
_find_all_elements = XPath(".//*")
|
_find_all_elements = XPath(".//*")
|
||||||
|
_find_all_elements_with_spaces = XPath(
|
||||||
|
".//*[normalize-space(text())]"
|
||||||
|
) # This selector gets all elements with text content
|
||||||
|
|
||||||
|
|
||||||
class Selector(SelectorsGeneration):
|
class Selector(SelectorsGeneration):
|
||||||
@@ -1161,10 +1164,7 @@ class Selector(SelectorsGeneration):
|
|||||||
if not case_sensitive:
|
if not case_sensitive:
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
|
|
||||||
# This selector gets all elements with text content
|
for node in self.__handle_elements(_find_all_elements_with_spaces(self._root)):
|
||||||
for node in self.__handle_elements(
|
|
||||||
self._root.xpath(".//*[normalize-space(text())]")
|
|
||||||
):
|
|
||||||
"""Check if element matches given text otherwise, traverse the children tree and iterate"""
|
"""Check if element matches given text otherwise, traverse the children tree and iterate"""
|
||||||
node_text = node.text
|
node_text = node.text
|
||||||
if clean_match:
|
if clean_match:
|
||||||
@@ -1203,10 +1203,7 @@ class Selector(SelectorsGeneration):
|
|||||||
"""
|
"""
|
||||||
results = Selectors()
|
results = Selectors()
|
||||||
|
|
||||||
# This selector gets all elements with text content
|
for node in self.__handle_elements(_find_all_elements_with_spaces(self._root)):
|
||||||
for node in self.__handle_elements(
|
|
||||||
self._root.xpath(".//*[normalize-space(text())]")
|
|
||||||
):
|
|
||||||
"""Check if element matches given regex otherwise, traverse the children tree and iterate"""
|
"""Check if element matches given regex otherwise, traverse the children tree and iterate"""
|
||||||
node_text = node.text
|
node_text = node.text
|
||||||
if node_text.re(
|
if node_text.re(
|
||||||
|
|||||||
Reference in New Issue
Block a user