mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-09-15 06:59:34 +02:00
perf: skip NFD normalization for ASCII paths
This commit is contained in:
@@ -10,7 +10,10 @@ def norm_path(path: Path | str, case_sensitive: bool) -> Path:
|
||||
"""Return `path` normalized to Unicode Normalization Form D (NFD)."""
|
||||
if isinstance(path, str):
|
||||
path = Path(path)
|
||||
normalized = unicodedata.normalize("NFD", path.as_posix())
|
||||
posix = path.as_posix()
|
||||
# NOTE: ASCII paths will be unaffected by all unicode normalization and can be skipped.
|
||||
# See: https://unicode.org/reports/tr15/
|
||||
normalized = posix if posix.isascii() else unicodedata.normalize("NFD", posix)
|
||||
if not case_sensitive:
|
||||
normalized = normalized.casefold()
|
||||
return Path(normalized)
|
||||
|
||||
Reference in New Issue
Block a user