mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
perf: Optimize Collection.equals() to reduce redundant map lookups (#11344)
* Initial plan * Optimize Collection.equals() to avoid redundant map lookups Co-authored-by: iCrawl <20760160+iCrawl@users.noreply.github.com> * Add explanatory comment for equals() undefined check optimization Co-authored-by: iCrawl <20760160+iCrawl@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: iCrawl <20760160+iCrawl@users.noreply.github.com> Co-authored-by: Almeida <github@almeidx.dev> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -822,7 +822,11 @@ export class Collection<Key, Value> extends Map<Key, Value> {
|
||||
if (this === collection) return true;
|
||||
if (this.size !== collection.size) return false;
|
||||
for (const [key, value] of this) {
|
||||
if (!collection.has(key) || value !== collection.get(key)) {
|
||||
const otherValue = collection.get(key);
|
||||
// If values differ, collections aren't equal.
|
||||
// For undefined values, we must also verify the key exists in the other collection,
|
||||
// since get() returns undefined for both missing keys and keys with undefined values.
|
||||
if (otherValue !== value || (otherValue === undefined && !collection.has(key))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user