mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-21 10:50:07 +00:00
perf(collection): avoid duplicated population of new collections (#11473)
This commit is contained in:
@@ -1023,7 +1023,10 @@ export class Collection<Key, Value> extends Map<Key, Value> {
|
||||
* but returns a Collection instead of an Array.
|
||||
*/
|
||||
public toReversed() {
|
||||
return new this.constructor[Symbol.species](this).reverse();
|
||||
const entries = [...this.entries()];
|
||||
entries.reverse();
|
||||
|
||||
return new this.constructor[Symbol.species](entries);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1039,7 +1042,10 @@ export class Collection<Key, Value> extends Map<Key, Value> {
|
||||
* ```
|
||||
*/
|
||||
public toSorted(compareFunction: Comparator<Key, Value> = Collection.defaultSort): Collection<Key, Value> {
|
||||
return new this.constructor[Symbol.species](this).sort(compareFunction);
|
||||
const entries = [...this.entries()];
|
||||
entries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0]));
|
||||
|
||||
return new this.constructor[Symbol.species](entries);
|
||||
}
|
||||
|
||||
public toJSON() {
|
||||
|
||||
Reference in New Issue
Block a user