Skip to content

Commit

Permalink
Small performance improvement for constructng new URL objects
Browse files Browse the repository at this point in the history
Avoids the NamedTuple property accesses since we already have the values
  • Loading branch information
bdraco committed Oct 19, 2024
1 parent 7d76bed commit 4ed563e
Showing 1 changed file with 8 additions and 4 deletions.
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 4ed563e

Please sign in to comment.