mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Revert "Cache array and keyArray in Collection (#771)"
This reverts commit 53f5c2cb52.
This commit is contained in:
@@ -3,16 +3,6 @@
|
|||||||
* @extends {Map}
|
* @extends {Map}
|
||||||
*/
|
*/
|
||||||
class Collection extends Map {
|
class Collection extends Map {
|
||||||
set(key, value) {
|
|
||||||
super.set(key, value);
|
|
||||||
this.changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(key) {
|
|
||||||
super.delete(key);
|
|
||||||
this.changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an ordered array of the values of this collection.
|
* Returns an ordered array of the values of this collection.
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
@@ -77,11 +67,8 @@ class Collection extends Map {
|
|||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
random() {
|
random() {
|
||||||
if (!this.cachedArray || this.cachedArray.length !== this.size || this.changed) {
|
const arr = this.array();
|
||||||
this.cachedArray = this.array();
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
this.changed = false;
|
|
||||||
}
|
|
||||||
return this.cachedArray[Math.floor(Math.random() * this.cachedArray.length)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,11 +77,8 @@ class Collection extends Map {
|
|||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
randomKey() {
|
randomKey() {
|
||||||
if (!this.cachedKeyArray || this.cachedKeyArray.length !== this.size || this.changed) {
|
const arr = this.keyArray();
|
||||||
this.cachedKeyArray = this.keyArray();
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
this.changed = false;
|
|
||||||
}
|
|
||||||
return this.cachedKeyArray[Math.floor(Math.random() * this.cachedKeyArray.length)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user