Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseObject String(value) 替换为 value.toString() 提高性能 #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DragonBones/src/dragonBones/core/BaseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace dragonBones {
private static readonly _poolsMap: Map<Array<BaseObject>> = {};

private static _returnObject(object: BaseObject): void {
const classType = String(object.constructor);
const classType = object.constructor.toString();
const maxCount = classType in BaseObject._maxCountMap ? BaseObject._maxCountMap[classType] : BaseObject._defaultMaxCount;
const pool = BaseObject._poolsMap[classType] = BaseObject._poolsMap[classType] || [];
if (pool.length < maxCount) {
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace dragonBones {
}

if (objectConstructor !== null) {
const classType = String(objectConstructor);
const classType = objectConstructor.toString();
const pool = classType in BaseObject._poolsMap ? BaseObject._poolsMap[classType] : null;
if (pool !== null && pool.length > maxCount) {
pool.length = maxCount;
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace dragonBones {
*/
public static clearPool(objectConstructor: (typeof BaseObject) | null = null): void {
if (objectConstructor !== null) {
const classType = String(objectConstructor);
const classType = objectConstructor.toString();
const pool = classType in BaseObject._poolsMap ? BaseObject._poolsMap[classType] : null;
if (pool !== null && pool.length > 0) {
pool.length = 0;
Expand All @@ -142,7 +142,7 @@ namespace dragonBones {
* @language zh_CN
*/
public static borrowObject<T extends BaseObject>(objectConstructor: { new(): T; }): T {
const classType = String(objectConstructor);
const classType = objectConstructor.toString();
const pool = classType in BaseObject._poolsMap ? BaseObject._poolsMap[classType] : null;
if (pool !== null && pool.length > 0) {
const object = pool.pop() as T;
Expand Down Expand Up @@ -183,4 +183,4 @@ namespace dragonBones {
BaseObject._returnObject(this);
}
}
}
}