Skip to content

Commit b07cbb8

Browse files
authored
Improve performance of converting a URL to a string (#1422)
1 parent b31eaa1 commit b07cbb8

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGES/1422.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved performance of converting :class:`~yarl.URL` to a string -- by :user:`bdraco`.

yarl/_parse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ def unsplit_result(
145145
"""Unsplit a URL without any normalization."""
146146
if netloc or (scheme and scheme in USES_AUTHORITY) or url[:2] == "//":
147147
if url and url[:1] != "/":
148-
url = f"//{netloc or ''}/{url}"
148+
url = f"{scheme}://{netloc}/{url}" if scheme else f"{scheme}:{url}"
149149
else:
150-
url = f"//{netloc or ''}{url}"
151-
if scheme:
150+
url = f"{scheme}://{netloc}{url}" if scheme else f"//{netloc}{url}"
151+
elif scheme:
152152
url = f"{scheme}:{url}"
153153
if query:
154154
url = f"{url}?{query}"

0 commit comments

Comments
 (0)