pool池优化性能
This commit is contained in:
@@ -14,7 +14,7 @@ module es {
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (let i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.get(type).unshift([]);
|
||||
this._objectQueue.get(type).push([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,14 +52,14 @@ module es {
|
||||
* 将项推回堆栈
|
||||
* @param obj
|
||||
*/
|
||||
public static free<T>(type: new (...args) => T, obj: Array<T>) {
|
||||
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);
|
||||
obj.length = 0;
|
||||
}
|
||||
|
||||
private static checkCreate<T>(type: new (...args) => T) {
|
||||
if (!this._objectQueue.get(type))
|
||||
if (!this._objectQueue.has(type))
|
||||
this._objectQueue.set(type, []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ module es {
|
||||
this._timeInSeconds = timeInsSeconds;
|
||||
this._repeats = repeats;
|
||||
this.context = context;
|
||||
this._onTime = onTime;
|
||||
this._onTime = onTime.bind(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@ module es {
|
||||
for (let i = this._timers.length - 1; i >= 0; i --){
|
||||
if (this._timers[i].tick()){
|
||||
this._timers[i].unload();
|
||||
new es.List(this._timers).removeAt(i);
|
||||
this._timers.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user