Skip to content

Commit

Permalink
Small performance improvements to checking for chars in paths (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 10, 2024
1 parent eaf7641 commit b77cc35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/1143.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of processing paths -- by :user:`bdraco`.
6 changes: 3 additions & 3 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def raw_parts(self) -> Tuple[str, ...]:
else:
parts = ["/"] + path[1:].split("/")
else:
if path.startswith("/"):
if path and path[0] == "/":
parts = ["/"] + path[1:].split("/")
else:
parts = path.split("/")
Expand Down Expand Up @@ -868,7 +868,7 @@ def _validate_authority_uri_abs_path(host: str, path: str) -> None:
Raise ValueError if not.
"""
if host and path and not path.startswith("/"):
if host and path and not path[0] == "/":
raise ValueError(
"Path in a URL with authority should start with a slash ('/') if set"
)
Expand Down Expand Up @@ -1395,7 +1395,7 @@ def with_suffix(self, suffix: str) -> "URL":
"""
if not isinstance(suffix, str):
raise TypeError("Invalid suffix type")
if suffix and not suffix.startswith(".") or suffix == ".":
if suffix and not suffix[0] == "." or suffix == ".":
raise ValueError(f"Invalid suffix {suffix!r}")
name = self.raw_name
if not name:
Expand Down

0 comments on commit b77cc35

Please sign in to comment.