Skip to content

Commit

Permalink
Small performance improvement for constructng new URL objects (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 19, 2024
1 parent 609d16d commit 5803ffc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/1336.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of constructing :class:`~yarl.URL` -- by :user:`bdraco`.
12 changes: 8 additions & 4 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def __new__(
if not encoded:
host: Union[str, None]
scheme, netloc, path, query, fragment = val
orig_netloc = netloc
orig_path = path
orig_query = query
orig_fragment = fragment
if not netloc: # netloc
host = ""
else:
Expand Down Expand Up @@ -312,10 +316,10 @@ def __new__(
# so we can avoid the extra work of creating a new SplitResult
# if the input SplitResult is already normalized
if (
val.netloc != netloc
or val.path != path
or val.query != query
or val.fragment != fragment
orig_netloc != netloc
or orig_path != path
or orig_query != query
or orig_fragment != fragment
):
# Constructing the tuple directly to avoid the overhead of
# the lambda and arg processing since NamedTuples are constructed
Expand Down

0 comments on commit 5803ffc

Please sign in to comment.