From 8e9a2b4630f78bb9e45345ec2a16812bfac70a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aura=20Rom=C3=A1n?= Date: Fri, 5 May 2023 14:49:00 +0200 Subject: [PATCH] perf(Role): linear speed position getter (#9493) Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/discord.js/src/structures/Role.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/Role.js b/packages/discord.js/src/structures/Role.js index 4acc806e8..d7cd97bad 100644 --- a/packages/discord.js/src/structures/Role.js +++ b/packages/discord.js/src/structures/Role.js @@ -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, + ); } /**