Skip to content

Commit

Permalink
perf(RoleManager): dont call Role#position getter twice per role (#9352)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
almeidx and kodiakhq[bot] committed Apr 9, 2023
1 parent fbbce3e commit bfee6c8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/discord.js/src/managers/RoleManager.js
Expand Up @@ -307,11 +307,14 @@ class RoleManager extends CachedManager {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'Role nor a Snowflake');
}

if (resolvedRole1.position === resolvedRole2.position) {
const role1Position = resolvedRole1.position;
const role2Position = resolvedRole2.position;

if (role1Position === role2Position) {
return Number(BigInt(resolvedRole2.id) - BigInt(resolvedRole1.id));
}

return resolvedRole1.position - resolvedRole2.position;
return role1Position - role2Position;
}

/**
Expand Down

0 comments on commit bfee6c8

Please sign in to comment.