pool池优化性能

This commit is contained in:
YHH
2022-03-07 22:52:51 +08:00
parent e207952786
commit 131df181e6
10 changed files with 120 additions and 131 deletions

View File

@@ -15,7 +15,7 @@ module es {
cacheCount -= this._objectQueue.get(type).length;
if (cacheCount > 0) {
for (let i = 0; i < cacheCount; i++) {
this._objectQueue.get(type).unshift(new type());
this._objectQueue.get(type).push(new type());
}
}
}
@@ -27,7 +27,7 @@ module es {
public static trimCache<T>(type: new (...args) => T, cacheCount: number) {
this.checkCreate(type);
while (cacheCount > this._objectQueue.get(type).length)
this._objectQueue.get(type).shift();
this._objectQueue.get(type).splice(0, 1);
}
/**
@@ -55,7 +55,7 @@ module es {
*/
public static free<T>(type: new (...args) => T, obj: T) {
this.checkCreate(type);
this._objectQueue.get(type).unshift(obj);
this._objectQueue.get(type).push(obj);
if (isIPoolable(obj)) {
obj["reset"]();
@@ -63,7 +63,7 @@ module es {
}
private static checkCreate<T>(type: new (...args) => T) {
if (!this._objectQueue.get(type))
if (!this._objectQueue.has(type))
this._objectQueue.set(type, []);
}
}