mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
optimize getComponent performance
optimize getComponent performance optimize getComponent performance optimize getComponent performance
This commit is contained in:
@@ -922,6 +922,11 @@ function CCClass (options) {
|
||||
name = cc.js.getClassName(cls);
|
||||
}
|
||||
|
||||
cls._sealed = true;
|
||||
if (base) {
|
||||
base._sealed = false;
|
||||
}
|
||||
|
||||
// define Properties
|
||||
var properties = options.properties;
|
||||
if (typeof properties === 'function' ||
|
||||
|
||||
@@ -51,20 +51,40 @@ function getConstructor(typeOrClassName) {
|
||||
}
|
||||
|
||||
function findComponent(node, constructor) {
|
||||
for (var i = 0; i < node._components.length; ++i) {
|
||||
var comp = node._components[i];
|
||||
if (comp instanceof constructor) {
|
||||
return comp;
|
||||
if (constructor._sealed) {
|
||||
for (let i = 0; i < node._components.length; ++i) {
|
||||
let comp = node._components[i];
|
||||
if (comp.constructor === constructor) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < node._components.length; ++i) {
|
||||
let comp = node._components[i];
|
||||
if (comp instanceof constructor) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function findComponents(node, constructor, components) {
|
||||
for (var i = 0; i < node._components.length; ++i) {
|
||||
var comp = node._components[i];
|
||||
if (comp instanceof constructor) {
|
||||
components.push(comp);
|
||||
if (constructor._sealed) {
|
||||
for (let i = 0; i < node._components.length; ++i) {
|
||||
let comp = node._components[i];
|
||||
if (comp.constructor === constructor) {
|
||||
components.push(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < node._components.length; ++i) {
|
||||
let comp = node._components[i];
|
||||
if (comp instanceof constructor) {
|
||||
components.push(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user