1
1
mirror of https://github.com/Byron/gitoxide synced 2025-10-06 01:52:40 +02:00

perf(gix-utils): add normalization fast path

This commit is contained in:
David Knaack
2025-08-17 13:43:43 +02:00
parent d8fbe1e7b7
commit 0e5d96188a

View File

@@ -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())