From a5de0c03bf40f81b4bd0740eeb9019500b2d53f7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 12 Oct 2024 21:32:03 -0500 Subject: [PATCH] Avoid copying list to reverse segments when making children (#1250) --- CHANGES/1250.misc.rst | 1 + yarl/_url.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 120000 CHANGES/1250.misc.rst diff --git a/CHANGES/1250.misc.rst b/CHANGES/1250.misc.rst new file mode 120000 index 000000000..7d8ab763d --- /dev/null +++ b/CHANGES/1250.misc.rst @@ -0,0 +1 @@ +1248.misc.rst \ No newline at end of file diff --git a/yarl/_url.py b/yarl/_url.py index 898118f80..f59f7f860 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -959,7 +959,8 @@ def _make_child(self, paths: "Sequence[str]", encoded: bool = False) -> "URL": ) path = path if encoded else self._PATH_QUOTER(path) needs_normalize |= "." in path - segments = list(reversed(path.split("/"))) + segments = path.split("/") + segments.reverse() # remove trailing empty segment for all but the last path segment_slice_start = int(not last and segments[0] == "") parsed += segments[segment_slice_start:]