Skip to content

Commit

Permalink
Small optimization to encoding hosts (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 7, 2024
1 parent 164a045 commit 4b26f03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/1125.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of encoding non IPv6 hosts -- by :user:`bdraco`.
7 changes: 6 additions & 1 deletion yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,12 @@ def _normalize_path(cls, path: str) -> str:

@classmethod
def _encode_host(cls, host: str, human: bool = False) -> str:
raw_ip, sep, zone = host.partition("%")
if "%" in host:
raw_ip, sep, zone = host.partition("%")
else:
raw_ip = host
sep = zone = ""

if raw_ip and raw_ip[-1].isdigit() or ":" in raw_ip:
# Might be an IP address, check it
#
Expand Down

0 comments on commit 4b26f03

Please sign in to comment.