Skip to content

Commit

Permalink
perf(Role): linear speed position getter (#9493)
Browse files Browse the repository at this point in the history
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
kyranet and Jiralite committed May 5, 2023
1 parent d4f12e0 commit 8e9a2b4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/discord.js/src/structures/Role.js
Expand Up @@ -188,8 +188,14 @@ class Role extends Base {
* @readonly
*/
get position() {
const sorted = this.guild._sortedRoles();
return [...sorted.values()].indexOf(sorted.get(this.id));
return this.guild.roles.cache.reduce(
(acc, role) =>
acc +
(this.rawPosition === role.rawPosition
? BigInt(this.id) > BigInt(role.id)
: this.rawPosition > role.rawPosition),
0,
);
}

/**
Expand Down

0 comments on commit 8e9a2b4

Please sign in to comment.