Skip to content

Commit

Permalink
Improve performance of converting a URL to a string (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 19, 2024
1 parent b31eaa1 commit b07cbb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/1422.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of converting :class:`~yarl.URL` to a string -- by :user:`bdraco`.
6 changes: 3 additions & 3 deletions yarl/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def unsplit_result(
"""Unsplit a URL without any normalization."""
if netloc or (scheme and scheme in USES_AUTHORITY) or url[:2] == "//":
if url and url[:1] != "/":
url = f"//{netloc or ''}/{url}"
url = f"{scheme}://{netloc}/{url}" if scheme else f"{scheme}:{url}"
else:
url = f"//{netloc or ''}{url}"
if scheme:
url = f"{scheme}://{netloc}{url}" if scheme else f"//{netloc}{url}"
elif scheme:
url = f"{scheme}:{url}"
if query:
url = f"{url}?{query}"
Expand Down

0 comments on commit b07cbb8

Please sign in to comment.