From 0e5d96188ac033d5b30bf83b1820da349c53a3b1 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sun, 17 Aug 2025 13:43:43 +0200 Subject: [PATCH] perf(gix-utils): add normalization fast path --- gix-utils/src/str.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gix-utils/src/str.rs b/gix-utils/src/str.rs index 335a32bf4fa..c13ffb0cfcc 100644 --- a/gix-utils/src/str.rs +++ b/gix-utils/src/str.rs @@ -4,8 +4,8 @@ use std::{borrow::Cow, ffi::OsStr, path::Path}; /// /// At the expense of extra-compute, it does nothing if there is no work to be done, returning the original input without allocating. pub fn precompose(s: Cow<'_, str>) -> Cow<'_, str> { - use unicode_normalization::UnicodeNormalization; - if s.as_ref().nfc().cmp(s.as_ref().chars()).is_eq() { + use unicode_normalization::{is_nfc, UnicodeNormalization}; + if is_nfc(s.as_ref()) { s } else { Cow::Owned(s.as_ref().nfc().collect()) @@ -16,8 +16,8 @@ pub fn precompose(s: Cow<'_, str>) -> Cow<'_, str> { /// /// At the expense of extra-compute, it does nothing if there is no work to be done, returning the original input without allocating. pub fn decompose(s: Cow<'_, str>) -> Cow<'_, str> { - use unicode_normalization::UnicodeNormalization; - if s.as_ref().nfd().cmp(s.as_ref().chars()).is_eq() { + use unicode_normalization::{is_nfd, UnicodeNormalization}; + if is_nfd(s.as_ref()) { s } else { Cow::Owned(s.as_ref().nfd().collect())