Files
esengine/source/src/Utils/ListPool.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

/**
*
*/
class ListPool {
private static readonly _objectQueue = [];
/**
* 使cacheCount对象填充缓存
* @param cacheCount
*/
public static warmCache(cacheCount: number){
cacheCount -= this._objectQueue.length;
if (cacheCount > 0){
for (let i = 0; i < cacheCount; i ++){
this._objectQueue.unshift([]);
}
}
}
/**
* cacheCount项目
* @param cacheCount
*/
public static trimCache(cacheCount){
while (cacheCount > this._objectQueue.length)
this._objectQueue.shift();
}
/**
*
*/
public static clearCache(){
this._objectQueue.length = 0;
}
/**
*
*/
2020-07-22 20:07:14 +08:00
public static obtain<T>(): T[] {
if (this._objectQueue.length > 0)
return this._objectQueue.shift();
return [];
}
/**
*
* @param obj
*/
public static free<T>(obj: Array<T>){
this._objectQueue.unshift(obj);
obj.length = 0;
}
}