mirror of
https://github.com/flectar/mail.git
synced 2026-11-12 10:15:19 +00:00
perf: hash ASCII contact addresses directly
This commit is contained in:
1 parent
2aca598c8f
commit
08f730d78e
1 file changed
+10
-1
+10
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user