java-topology/defects/cpython/patch/0001-pkgutil-extend-path-set-dedup.patch

22 lines
891 B
Diff

# UNDF: UNDF-2026-000000039
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -301,6 +301,7 @@ def extend_path(path, name):
path = path[:] # Start with a copy of the existing path
+ path_set = set(path) # O(1) membership — avoids O(n²) in the loop below
parent_package, _, final_name = name.rpartition('.')
if parent_package:
@@ -320,9 +321,10 @@ def extend_path(path, name):
for portion in portions:
# XXX This may still add duplicate entries to path on
# case-insensitive filesystems
- if portion not in path:
+ if portion not in path_set:
path.append(portion)
+ path_set.add(portion)
# XXX Is this the right thing for subpackages like zope.app?
# It looks for a file named "zope.app.pkg"