diff --git a/CHANGES/1336.misc.rst b/CHANGES/1336.misc.rst new file mode 100644 index 000000000..c62fc0b17 --- /dev/null +++ b/CHANGES/1336.misc.rst @@ -0,0 +1 @@ +Improved performance of constructing :class:`~yarl.URL` -- by :user:`bdraco`. diff --git a/yarl/_url.py b/yarl/_url.py index 7ef4ae702..5a0be4514 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -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: @@ -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