1
0
Fork 0

Improve perf due to slow localeCompare

This commit is contained in:
Lim Chee Aun 2023-12-22 00:26:29 +08:00
parent 3e4e4d179b
commit 5f48f92c11

View file

@ -7,6 +7,10 @@ import states from '../utils/states';
import Avatar from './avatar'; import Avatar from './avatar';
import EmojiText from './emoji-text'; import EmojiText from './emoji-text';
const nameCollator = new Intl.Collator('en', {
sensitivity: 'base',
});
function NameText({ function NameText({
account, account,
instance, instance,
@ -36,9 +40,7 @@ function NameText({
(trimmedUsername === trimmedDisplayName || (trimmedUsername === trimmedDisplayName ||
trimmedUsername === shortenedDisplayName || trimmedUsername === shortenedDisplayName ||
trimmedUsername === shortenedAlphaNumericDisplayName || trimmedUsername === shortenedAlphaNumericDisplayName ||
trimmedUsername.localeCompare?.(shortenedDisplayName, 'en', { nameCollator.compare(trimmedUsername, shortenedDisplayName) === 0)
sensitivity: 'base',
}) === 0)
) { ) {
username = null; username = null;
} }