Skip to content

Commit 20b7c20

Browse files
authored
Merge pull request #2120 from davidkna/norm-fast-path
perf(gix-utils): add normalization fast path
2 parents f3be6e3 + 0e5d961 commit 20b7c20

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

gix-utils/src/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::{borrow::Cow, ffi::OsStr, path::Path};
44
///
55
/// At the expense of extra-compute, it does nothing if there is no work to be done, returning the original input without allocating.
66
pub fn precompose(s: Cow<'_, str>) -> Cow<'_, str> {
7-
use unicode_normalization::UnicodeNormalization;
8-
if s.as_ref().nfc().cmp(s.as_ref().chars()).is_eq() {
7+
use unicode_normalization::{is_nfc, UnicodeNormalization};
8+
if is_nfc(s.as_ref()) {
99
s
1010
} else {
1111
Cow::Owned(s.as_ref().nfc().collect())
@@ -16,8 +16,8 @@ pub fn precompose(s: Cow<'_, str>) -> Cow<'_, str> {
1616
///
1717
/// At the expense of extra-compute, it does nothing if there is no work to be done, returning the original input without allocating.
1818
pub fn decompose(s: Cow<'_, str>) -> Cow<'_, str> {
19-
use unicode_normalization::UnicodeNormalization;
20-
if s.as_ref().nfd().cmp(s.as_ref().chars()).is_eq() {
19+
use unicode_normalization::{is_nfd, UnicodeNormalization};
20+
if is_nfd(s.as_ref()) {
2121
s
2222
} else {
2323
Cow::Owned(s.as_ref().nfd().collect())

0 commit comments

Comments
 (0)