logoalt Hacker News

How we made Python's packaging library 3x faster

47 pointsby rbanffylast Friday at 8:00 AM6 commentsview on HN

Comments

djoldmantoday at 1:27 AM

> _canonicalize_table = str.maketrans( "ABCDEFGHIJKLMNOPQRSTUVWXYZ_.", "abcdefghijklmnopqrstuvwxyz--", )

> ...

> value = name.translate(_canonicalize_table)

> while "--" in value:

> value = value.replace("--", "-")

translate can be wildly fast compared to some commonly used regexes or replacements.

show 2 replies