Skip to content

Commit

Permalink
Fix object pool to generate unique pool hash for every instance
Browse files Browse the repository at this point in the history
  • Loading branch information
DrA1ex committed Oct 7, 2023
1 parent 8e1579a commit 4554d3e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/misc/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @template T
*/
export class ObjectPool {
static #hashKey = Symbol();
#hashKey = Symbol();

/** @type {Map<number, T>} */
#used = new Map();
Expand Down Expand Up @@ -41,8 +41,8 @@ export class ObjectPool {
}

const value = this.#spawnFn();
value[ObjectPool.#hashKey] = this.#id++;
this.#used.set(value[ObjectPool.#hashKey], value);
value[this.#hashKey] = this.#id++;
this.#used.set(value[this.#hashKey], value);

return value;
}
Expand All @@ -51,7 +51,7 @@ export class ObjectPool {
* @param {T} object
*/
free(object) {
const hash = object[ObjectPool.#hashKey];
const hash = object[this.#hashKey];
if (hash === undefined) {
console.warn(`Trying to free non-pool object ${object}`);
return;
Expand All @@ -69,7 +69,7 @@ export class ObjectPool {
}

detach(object) {
const hash = object[ObjectPool.#hashKey];
const hash = object[this.#hashKey];
if (hash === undefined) {
console.warn(`Trying to detach non-pool object ${object}`);
return;
Expand Down

0 comments on commit 4554d3e

Please sign in to comment.