File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -890,6 +890,13 @@ def search(self, prepared: Prepared):
890890 return itertools .chain (infos , eggs )
891891
892892
893+ # Translation table for Prepared.normalize: lowercase and replace - . with _
894+ _normalize_table = str .maketrans (
895+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ-." ,
896+ "abcdefghijklmnopqrstuvwxyz__" ,
897+ )
898+
899+
893900class Prepared :
894901 """
895902 A prepared search query for metadata on a possibly-named package.
@@ -925,7 +932,13 @@ def normalize(name):
925932 """
926933 PEP 503 normalization plus dashes as underscores.
927934 """
928- return re .sub (r"[-_.]+" , "-" , name ).lower ().replace ('-' , '_' )
935+ # Emulates ``re.sub(r"[-_.]+", "-", name).lower()`` from PEP 503
936+ # About 3x faster, safe since packages only support alphanumeric characters
937+ value = name .translate (_normalize_table )
938+ # Condense repeats (faster than regex)
939+ while "__" in value :
940+ value = value .replace ("__" , "_" )
941+ return value
929942
930943 @staticmethod
931944 def legacy_normalize (name ):
You can’t perform that action at this time.
0 commit comments