mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15605 from minggo/node-enumerate-issue
reduce loop times to be quicker on low performace devices
This commit is contained in:
commit
a1ddb53b06
|
@ -1309,19 +1309,18 @@ void NodeNameTest::test(float dt)
|
||||||
});
|
});
|
||||||
CCAssert(i == 1, "");
|
CCAssert(i == 1, "");
|
||||||
|
|
||||||
|
|
||||||
// enumerateChildren
|
// enumerateChildren
|
||||||
// name = node[[digit]]+/node
|
// name = node[[digit]]+/node
|
||||||
|
|
||||||
parent = Node::create();
|
parent = Node::create();
|
||||||
for (int i = 0; i < 100; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
auto node = Node::create();
|
auto node = Node::create();
|
||||||
sprintf(name, "node%d", i);
|
sprintf(name, "node%d", i);
|
||||||
node->setName(name);
|
node->setName(name);
|
||||||
parent->addChild(node);
|
parent->addChild(node);
|
||||||
|
|
||||||
for (int j = 0; j < 100; ++j)
|
for (int j = 0; j < 10; ++j)
|
||||||
{
|
{
|
||||||
auto child = Node::create();
|
auto child = Node::create();
|
||||||
child->setName("node");
|
child->setName("node");
|
||||||
|
@ -1334,7 +1333,7 @@ void NodeNameTest::test(float dt)
|
||||||
++i;
|
++i;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
CCAssert(i == 100, "");
|
CCAssert(i == 10, "");
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
parent->enumerateChildren("node1/node", [&i](Node* node) -> bool {
|
parent->enumerateChildren("node1/node", [&i](Node* node) -> bool {
|
||||||
|
@ -1345,14 +1344,14 @@ void NodeNameTest::test(float dt)
|
||||||
|
|
||||||
// search from root
|
// search from root
|
||||||
parent = Node::create();
|
parent = Node::create();
|
||||||
for (int i = 0; i < 100; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
auto node = Node::create();
|
auto node = Node::create();
|
||||||
sprintf(name, "node%d", i);
|
sprintf(name, "node%d", i);
|
||||||
node->setName(name);
|
node->setName(name);
|
||||||
parent->addChild(node);
|
parent->addChild(node);
|
||||||
|
|
||||||
for (int j = 0; j < 100; ++j)
|
for (int j = 0; j < 10; ++j)
|
||||||
{
|
{
|
||||||
auto child = Node::create();
|
auto child = Node::create();
|
||||||
child->setName("node");
|
child->setName("node");
|
||||||
|
@ -1365,7 +1364,7 @@ void NodeNameTest::test(float dt)
|
||||||
++i;
|
++i;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
CCAssert(i == 10000, "");
|
CCAssert(i == 100, "");
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
|
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
|
||||||
|
@ -1388,18 +1387,18 @@ void NodeNameTest::test(float dt)
|
||||||
++i;
|
++i;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
CCAssert(i == 10000, "");
|
CCAssert(i == 100, "");
|
||||||
|
|
||||||
// name = //xxx : search recursively
|
// name = //xxx : search recursively
|
||||||
parent = Node::create();
|
parent = Node::create();
|
||||||
for (int j = 0; j < 100; j++)
|
for (int j = 0; j < 10; j++)
|
||||||
{
|
{
|
||||||
auto node = Node::create();
|
auto node = Node::create();
|
||||||
sprintf(name, "node%d", j);
|
sprintf(name, "node%d", j);
|
||||||
node->setName(name);
|
node->setName(name);
|
||||||
parent->addChild(node);
|
parent->addChild(node);
|
||||||
|
|
||||||
for (int k = 0; k < 100; ++k)
|
for (int k = 0; k < 10; ++k)
|
||||||
{
|
{
|
||||||
auto child = Node::create();
|
auto child = Node::create();
|
||||||
sprintf(name, "node%d", k);
|
sprintf(name, "node%d", k);
|
||||||
|
@ -1413,7 +1412,7 @@ void NodeNameTest::test(float dt)
|
||||||
++i;
|
++i;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
CCAssert(i == 10100, ""); // 10000(children) + 100(parent)
|
CCAssert(i == 110, ""); // 100(children) + 10(parent)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
parent->enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
|
parent->enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||||
|
@ -1427,7 +1426,7 @@ void NodeNameTest::test(float dt)
|
||||||
++i;
|
++i;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
CCAssert(i == 10000, "");
|
CCAssert(i == 100, "");
|
||||||
|
|
||||||
// utils::findChildren()
|
// utils::findChildren()
|
||||||
|
|
||||||
|
@ -1440,5 +1439,4 @@ void NodeNameTest::test(float dt)
|
||||||
}
|
}
|
||||||
auto findChildren = utils::findChildren(*parent, "node");
|
auto findChildren = utils::findChildren(*parent, "node");
|
||||||
CCAssert(findChildren.size() == 50, "");
|
CCAssert(findChildren.size() == 50, "");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue