From fc69dabca27af11ea2508b7932559d3acf7bc94a Mon Sep 17 00:00:00 2001 From: joewanchen Date: Sun, 21 Dec 2014 00:22:23 +0800 Subject: [PATCH 1/6] fix serious performance problem. --- cocos/2d/CCActionInterval.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index 404416be59..6807d3414f 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -2237,7 +2237,7 @@ bool Animate::initWithAnimation(Animation* animation) float accumUnitsOfTime = 0; float newUnitOfTimeValue = singleDuration / animation->getTotalDelayUnits(); - auto frames = animation->getFrames(); + auto& frames = animation->getFrames(); for (auto& frame : frames) { @@ -2312,7 +2312,7 @@ void Animate::update(float t) t = fmodf(t, 1.0f); } - auto frames = _animation->getFrames(); + auto& frames = _animation->getFrames(); auto numberOfFrames = frames.size(); SpriteFrame *frameToDisplay = nullptr; From 7d6686eb7b12c50e43976f6ebae2f82571ba299d Mon Sep 17 00:00:00 2001 From: joewanchen Date: Sun, 21 Dec 2014 00:42:55 +0800 Subject: [PATCH 2/6] fix. --- cocos/2d/CCActionInterval.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index 6807d3414f..b265aca9d2 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -2346,7 +2346,7 @@ void Animate::update(float t) Animate* Animate::reverse() const { - auto oldArray = _animation->getFrames(); + auto& oldArray = _animation->getFrames(); Vector newArray(oldArray.size()); if (oldArray.size() > 0) From 3765f8765132a91d2562b404114ffe0206b848a3 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Sun, 21 Dec 2014 00:49:23 +0800 Subject: [PATCH 3/6] fix. --- cocos/2d/CCLabel.cpp | 2 +- cocos/base/CCConsole.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index b812d793d2..0d3d453285 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -591,7 +591,7 @@ void Label::alignText() batchNode->getTextureAtlas()->removeAllQuads(); } _fontAtlas->prepareLetterDefinitions(_currentUTF16String); - auto textures = _fontAtlas->getTextures(); + auto& textures = _fontAtlas->getTextures(); if (textures.size() > _batchNodes.size()) { for (auto index = _batchNodes.size(); index < textures.size(); ++index) diff --git a/cocos/base/CCConsole.cpp b/cocos/base/CCConsole.cpp index 673cefc62b..83b4403530 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -160,14 +160,14 @@ static void printFileUtils(int fd) FileUtils* fu = FileUtils::getInstance(); mydprintf(fd, "\nSearch Paths:\n"); - auto list = fu->getSearchPaths(); + auto& list = fu->getSearchPaths(); for( const auto &item : list) { mydprintf(fd, "%s\n", item.c_str()); } mydprintf(fd, "\nResolution Order:\n"); - list = fu->getSearchResolutionsOrder(); - for( const auto &item : list) { + auto& list1 = fu->getSearchResolutionsOrder(); + for( const auto &item : list1) { mydprintf(fd, "%s\n", item.c_str()); } @@ -175,7 +175,7 @@ static void printFileUtils(int fd) mydprintf(fd, "%s\n", fu->getWritablePath().c_str()); mydprintf(fd, "\nFull Path Cache:\n"); - auto cache = fu->getFullPathCache(); + auto& cache = fu->getFullPathCache(); for( const auto &item : cache) { mydprintf(fd, "%s -> %s\n", item.first.c_str(), item.second.c_str()); } From c2473b9b99028c884ec02b25ac197324b500af11 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Sun, 21 Dec 2014 01:03:30 +0800 Subject: [PATCH 4/6] fix. --- .../cocostudio/ActionTimeline/CCActionTimeline.cpp | 2 +- cocos/ui/UILayout.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp index 052f25b4f7..3f60a792ff 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp @@ -204,7 +204,7 @@ void foreachNodeDescendant(Node* parent, tCallBack callback) { callback(parent); - auto children = parent->getChildren(); + auto& children = parent->getChildren(); for (auto child : children) { foreachNodeDescendant(child, callback); diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 9b75316cbf..5325bd7934 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -1659,7 +1659,7 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)c return true; } - auto container = parent->getChildren(); + auto& container = parent->getChildren(); ssize_t index = container.getIndex(widget); if (parent->getLayoutType() == Type::HORIZONTAL) { From a15a4a0739ea5a192bcd9a08ba29f798b0e2d870 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Sun, 21 Dec 2014 02:03:41 +0800 Subject: [PATCH 5/6] fix compile error. --- cocos/2d/CCLabel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 0d3d453285..b812d793d2 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -591,7 +591,7 @@ void Label::alignText() batchNode->getTextureAtlas()->removeAllQuads(); } _fontAtlas->prepareLetterDefinitions(_currentUTF16String); - auto& textures = _fontAtlas->getTextures(); + auto textures = _fontAtlas->getTextures(); if (textures.size() > _batchNodes.size()) { for (auto index = _batchNodes.size(); index < textures.size(); ++index) From bb1267cd09a2e6f3f65f3f9d9644d21ef86e2cae Mon Sep 17 00:00:00 2001 From: joewanchen Date: Sun, 21 Dec 2014 14:05:34 +0800 Subject: [PATCH 6/6] use auto&. --- cocos/2d/CCLabel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index b812d793d2..6d1fd4aa07 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -591,12 +591,12 @@ void Label::alignText() batchNode->getTextureAtlas()->removeAllQuads(); } _fontAtlas->prepareLetterDefinitions(_currentUTF16String); - auto textures = _fontAtlas->getTextures(); + auto& textures = _fontAtlas->getTextures(); if (textures.size() > _batchNodes.size()) { for (auto index = _batchNodes.size(); index < textures.size(); ++index) { - auto batchNode = SpriteBatchNode::createWithTexture(textures[index]); + auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index)); batchNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); batchNode->setPosition(Vec2::ZERO); Node::addChild(batchNode,0,Node::INVALID_TAG); @@ -629,9 +629,9 @@ void Label::alignText() uvRect.origin.x = _lettersInfo[tag].def.U; uvRect.origin.y = _lettersInfo[tag].def.V; - letterSprite->setTexture(textures[_lettersInfo[tag].def.textureID]); + letterSprite->setTexture(textures.at(_lettersInfo[tag].def.textureID)); letterSprite->setTextureRect(uvRect); - } + } } }