From 562b62a5b625a667e58c1813724eb30e62007798 Mon Sep 17 00:00:00 2001 From: Schuyler Cebulskie Date: Sat, 22 Oct 2016 15:11:42 -0400 Subject: [PATCH] Revert "Cache array and keyArray in Collection (#771)" This reverts commit 53f5c2cb5282a857dd1a8e78038d6d5d65b078b0. --- src/util/Collection.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/util/Collection.js b/src/util/Collection.js index e40d93396..70b29b9c2 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -3,16 +3,6 @@ * @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 {Array} @@ -77,11 +67,8 @@ class Collection extends Map { * @returns {*} */ random() { - if (!this.cachedArray || this.cachedArray.length !== this.size || this.changed) { - this.cachedArray = this.array(); - this.changed = false; - } - return this.cachedArray[Math.floor(Math.random() * this.cachedArray.length)]; + const arr = this.array(); + return arr[Math.floor(Math.random() * arr.length)]; } /** @@ -90,11 +77,8 @@ class Collection extends Map { * @returns {*} */ randomKey() { - if (!this.cachedKeyArray || this.cachedKeyArray.length !== this.size || this.changed) { - this.cachedKeyArray = this.keyArray(); - this.changed = false; - } - return this.cachedKeyArray[Math.floor(Math.random() * this.cachedKeyArray.length)]; + const arr = this.keyArray(); + return arr[Math.floor(Math.random() * arr.length)]; } /**