Skip to content

Commit

Permalink
Speed up skipwrap function
Browse files Browse the repository at this point in the history
Short-circuit evaluation when `wrap_links` is True (the default).
Evaluating a boolean expression is much cheaper than searching a
paragraph for a match.

Any link present in the paragraph causes the wrapping to be skipped.
Instead of searching for all matches, stop at the first match.
  • Loading branch information
francoisfreitag authored and jdufresne committed Jan 16, 2020
1 parent 2d2c702 commit bd982bd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion html2text/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def list_numbering_start(attrs: Dict[str, Optional[str]]) -> int:
def skipwrap(para: str, wrap_links: bool, wrap_list_items: bool) -> bool:
# If it appears to contain a link
# don't wrap
if (len(config.RE_LINK.findall(para)) > 0) and not wrap_links:
if not wrap_links and config.RE_LINK.search(para):
return True
# If the text begins with four spaces or one tab, it's a code block;
# don't wrap
Expand Down

0 comments on commit bd982bd

Please sign in to comment.