Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significantly speed up parsing netloc in URL objects #1112

Merged
merged 33 commits into from
Sep 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tweaks to make it a bit more readable and avoid the getitems
bdraco committed Sep 6, 2024

Verified

This commit was signed with the committer’s verified signature.
bdraco J. Nick Koston
commit 454f6e603e100d8528e5fb749dd6237d30cdde20
17 changes: 9 additions & 8 deletions yarl/_url.py
Original file line number Diff line number Diff line change
@@ -213,8 +213,9 @@ def __new__(
cache: Dict[str, Union[str, int, None]] = {}
bdraco marked this conversation as resolved.
Show resolved Hide resolved
if not encoded:
host: Union[str, None]
if not val[1]: # netloc
host = netloc = ""
scheme, netloc, path, query, fragment = val
if not netloc: # netloc
host = ""
else:
username, password, host, port = cls._split_netloc(val[1])
if host is None:
@@ -236,17 +237,17 @@ def __new__(
cache["raw_user"] = raw_user
cache["raw_password"] = raw_password
cache["explicit_port"] = port
path = cls._PATH_REQUOTER(val[2])
if netloc:
path = cls._PATH_REQUOTER(path) if path else path
if netloc and path:
path = cls._normalize_path(path)

cls._validate_authority_uri_abs_path(host=host, path=path)
query = cls._QUERY_REQUOTER(val[3])
fragment = cls._FRAGMENT_REQUOTER(val[4])
cache["scheme"] = val[0]
query = cls._QUERY_REQUOTER(query) if query else query
fragment = cls._FRAGMENT_REQUOTER(query) if fragment else fragment
cache["scheme"] = scheme
cache["raw_query_string"] = query
cache["raw_fragment"] = fragment
val = SplitResult(val[0], netloc, path, query, fragment)
val = SplitResult(scheme, netloc, path, query, fragment)

self = object.__new__(cls)
self._val = val