diff --git a/src/uucore/src/lib/features/i18n/collator.rs b/src/uucore/src/lib/features/i18n/collator.rs index 007e17c90..9a8ee1fc6 100644 --- a/src/uucore/src/lib/features/i18n/collator.rs +++ b/src/uucore/src/lib/features/i18n/collator.rs @@ -74,6 +74,17 @@ pub fn init_locale_collation() -> bool { try_init_collator(opts) } +/// Compute the ICU collation sort key for the given input bytes and append it to `buf`. +/// This allows pre-computing sort keys once per line, then comparing them with simple +/// byte comparison during sorting (much faster than calling `compare_utf8` per comparison). +pub fn compute_sort_key_utf8(input: &[u8], buf: &mut Vec) { + let c = COLLATOR + .get() + .expect("compute_sort_key_utf8 called before collator initialization"); + c.write_sort_key_utf8_to(input, buf) + .expect("ICU write_sort_key_utf8_to failed"); +} + /// Compare both strings with regard to the current locale. pub fn locale_cmp(left: &[u8], right: &[u8]) -> Ordering { // If the detected locale is 'C', just do byte-wise comparison