From 08f730d78e1fe642ad0cd65ea8eee8f140c45d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Romero?= Date: Thu, 8 Oct 2026 13:25:05 +0000 Subject: [PATCH] perf: hash ASCII contact addresses directly --- src/contacts.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/contacts.rs b/src/contacts.rs index 3b713474..5ff59919 100644 --- a/src/contacts.rs +++ b/src/contacts.rs @@ -100,7 +100,16 @@ fn contact_avatar_tone(contact: &ContactRecord) -> i32 { // normalized email keeps the fallback consistent when a display name is // edited and avoids a visibly changing "random" color between launches. let mut hash = 0x811c_9dc5_u32; - for byte in contact.email.trim().to_lowercase().bytes() { + let email = contact.email.trim(); + // Unicode lowercasing can depend on surrounding characters (Greek sigma). + // Keep that normalization for non-ASCII addresses, but hash ordinary email + // bytes directly without an intermediate string. + let normalized = if email.is_ascii() { + std::borrow::Cow::Borrowed(email) + } else { + std::borrow::Cow::Owned(email.to_lowercase()) + }; + for byte in normalized.bytes().map(|byte| byte.to_ascii_lowercase()) { hash ^= u32::from(byte); hash = hash.wrapping_mul(0x0100_0193); }