1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Improve calculateRoomName performances by using Intl.Collator

This commit is contained in:
Germain Souquet
2021-07-21 14:18:22 +02:00
parent fb315ac75b
commit f708c47385
2 changed files with 11 additions and 1 deletions

View File

@@ -2053,7 +2053,7 @@ export class Room extends EventEmitter {
(m.membership === "invite" || m.membership === "join");
});
// make sure members have stable order
otherMembers.sort((a, b) => a.userId.localeCompare(b.userId));
otherMembers.sort((a, b) => utils.compare(a.userId, b.userId));
// only 5 first members, immitate summaryHeroes
otherMembers = otherMembers.slice(0, 5);
otherNames = otherMembers.map((m) => m.name);

View File

@@ -683,3 +683,13 @@ export function lexicographicCompare(a: string, b: string): number {
// hidden the operation in this function.
return (a < b) ? -1 : ((a === b) ? 0 : 1);
}
const collator = new Intl.Collator();
/**
* Performant language-sensitive string comparison
* @param a the first string to compare
* @param b the second string to compare
*/
export function compare(a: string, b: string): number {
return collator.compare(a, b);
}