From b4c72a3bd53392616c368cc976c3423af6fb11ad Mon Sep 17 00:00:00 2001 From: John Zhang Date: Thu, 27 Jun 2019 02:37:37 +0800 Subject: [PATCH 1/3] clang-tidy: performance-unnecessary-value-param --- .clang-tidy | 1 + cocos/3d/CCTerrain.cpp | 2 +- cocos/3d/CCTerrain.h | 2 +- cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp | 4 ++-- cocos/editor-support/cocosbuilder/CCBAnimationManager.h | 4 ++-- cocos/editor-support/cocosbuilder/CCBReader.cpp | 2 +- cocos/editor-support/cocosbuilder/CCBReader.h | 2 +- .../cocostudio/ActionTimeline/CCActionTimelineCache.cpp | 2 +- .../cocostudio/ActionTimeline/CCActionTimelineCache.h | 2 +- .../cocostudio/ActionTimeline/CCSkeletonNode.cpp | 2 +- .../cocostudio/ActionTimeline/CCSkeletonNode.h | 2 +- cocos/editor-support/cocostudio/CCSSceneReader.cpp | 2 +- cocos/editor-support/cocostudio/CCSSceneReader.h | 2 +- cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp | 6 +++--- cocos/editor-support/cocostudio/FlatBuffersSerialize.h | 6 +++--- .../cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp | 2 +- .../cocostudio/WidgetReader/ButtonReader/ButtonReader.h | 2 +- .../WidgetReader/GameNode3DReader/GameNode3DReader.cpp | 2 +- .../WidgetReader/GameNode3DReader/GameNode3DReader.h | 2 +- .../WidgetReader/ImageViewReader/ImageViewReader.cpp | 2 +- .../WidgetReader/ImageViewReader/ImageViewReader.h | 2 +- .../cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp | 2 +- .../cocostudio/WidgetReader/LayoutReader/LayoutReader.h | 2 +- .../WidgetReader/ListViewReader/ListViewReader.cpp | 2 +- .../WidgetReader/ListViewReader/ListViewReader.h | 2 +- .../WidgetReader/LoadingBarReader/LoadingBarReader.cpp | 2 +- .../WidgetReader/LoadingBarReader/LoadingBarReader.h | 2 +- .../WidgetReader/PageViewReader/PageViewReader.cpp | 2 +- .../WidgetReader/PageViewReader/PageViewReader.h | 2 +- .../WidgetReader/ScrollViewReader/ScrollViewReader.cpp | 2 +- .../WidgetReader/ScrollViewReader/ScrollViewReader.h | 2 +- .../cocostudio/WidgetReader/SliderReader/SliderReader.cpp | 2 +- .../cocostudio/WidgetReader/SliderReader/SliderReader.h | 2 +- .../cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp | 2 +- .../cocostudio/WidgetReader/SpriteReader/SpriteReader.h | 2 +- .../WidgetReader/TabControlReader/TabControlReader.cpp | 2 +- .../WidgetReader/TabControlReader/TabControlReader.h | 2 +- .../WidgetReader/UserCameraReader/UserCameraReader.cpp | 2 +- .../WidgetReader/UserCameraReader/UserCameraReader.h | 2 +- cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp | 2 +- .../js-bindings/auto/jsb_cocos2dx_extension_auto.cpp | 2 +- .../manual/extension/jsb_cocos2dx_extension_manual.cpp | 8 ++++---- tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp | 2 +- tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h | 2 +- .../cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp | 2 +- tests/lua-tests/project/Classes/lua_test_bindings.cpp | 4 ++-- 46 files changed, 56 insertions(+), 55 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 239e21fbb15e..9d42e439cd29 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,7 @@ Checks: > performance-move-constructor-init, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, + -performance-unnecessary-value-param, readability-container-size-empty, readability-delete-null-pointer, readability-redundant-control-flow, diff --git a/cocos/3d/CCTerrain.cpp b/cocos/3d/CCTerrain.cpp index decffa720a24..0c12d3260ee5 100644 --- a/cocos/3d/CCTerrain.cpp +++ b/cocos/3d/CCTerrain.cpp @@ -700,7 +700,7 @@ void Terrain::setAlphaMap(cocos2d::Texture2D * newAlphaMapTexture) _alphaMap = newAlphaMapTexture; } -void Terrain::setDetailMap(unsigned int index, DetailMap detailMap) +void Terrain::setDetailMap(unsigned int index, const DetailMap& detailMap) { if(index>4) { diff --git a/cocos/3d/CCTerrain.h b/cocos/3d/CCTerrain.h index bfa7a4aca9e8..f385b995b0b2 100644 --- a/cocos/3d/CCTerrain.h +++ b/cocos/3d/CCTerrain.h @@ -369,7 +369,7 @@ class CC_DLL Terrain : public Node /** set the alpha map*/ void setAlphaMap(cocos2d::Texture2D * newAlphaMapTexture); /**set the Detail Map */ - void setDetailMap(unsigned int index, DetailMap detailMap); + void setDetailMap(unsigned int index, const DetailMap& detailMap); // Overrides, internal use only virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4 &transform, uint32_t flags) override; diff --git a/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp b/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp index 4481dee4332a..4560c6907c39 100644 --- a/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp +++ b/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp @@ -140,7 +140,7 @@ void CCBAnimationManager::addDocumentCallbackNode(Node *node) _documentCallbackNodes.pushBack(node); } -void CCBAnimationManager::addDocumentCallbackName(std::string name) +void CCBAnimationManager::addDocumentCallbackName(const std::string& name) { _documentCallbackNames.push_back(Value(name)); } @@ -170,7 +170,7 @@ void CCBAnimationManager::addDocumentOutletNode(Node *node) _documentOutletNodes.pushBack(node); } -void CCBAnimationManager::addDocumentOutletName(std::string name) +void CCBAnimationManager::addDocumentOutletName(const std::string& name) { _documentOutletNames.push_back(Value(name)); } diff --git a/cocos/editor-support/cocosbuilder/CCBAnimationManager.h b/cocos/editor-support/cocosbuilder/CCBAnimationManager.h index 474e8449f1e0..b0bb8c6426ce 100644 --- a/cocos/editor-support/cocosbuilder/CCBAnimationManager.h +++ b/cocos/editor-support/cocosbuilder/CCBAnimationManager.h @@ -76,11 +76,11 @@ class CC_DLL CCBAnimationManager : public cocos2d::Ref void addDocumentCallbackNode(cocos2d::Node *node); - void addDocumentCallbackName(std::string name); + void addDocumentCallbackName(const std::string& name); void addDocumentCallbackControlEvents(cocos2d::extension::Control::EventType eventType); void addDocumentOutletNode(cocos2d::Node *node); - void addDocumentOutletName(std::string name); + void addDocumentOutletName(const std::string& name); void setDocumentControllerName(const std::string &name); diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index f80b2100e635..5b5eb2a3f562 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -1069,7 +1069,7 @@ Vector& CCBReader::getAnimationManagersForNodes() return _animationManagersForNodes; } -void CCBReader::addOwnerOutletName(std::string name) +void CCBReader::addOwnerOutletName(const std::string& name) { _ownerOutletNames.push_back(name); } diff --git a/cocos/editor-support/cocosbuilder/CCBReader.h b/cocos/editor-support/cocosbuilder/CCBReader.h index 22208f88fe46..02f55f83cec6 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.h +++ b/cocos/editor-support/cocosbuilder/CCBReader.h @@ -372,7 +372,7 @@ class CC_DLL CCBReader : public cocos2d::Ref */ cocos2d::Node* readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am); - void addOwnerOutletName(std::string name); + void addOwnerOutletName(const std::string& name); void addOwnerOutletNode(cocos2d::Node *node); private: diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index 119a0d2e1221..ca482d3bc184 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -423,7 +423,7 @@ ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersFile(const std:: return action->clone(); } -ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(Data data, const std::string &fileName) +ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(const Data& data, const std::string &fileName) { ActionTimeline* action = _animationActions.at(fileName); if (action == NULL) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h index f315dae17e8a..21a2762581cd 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h @@ -85,7 +85,7 @@ class CC_STUDIO_DLL ActionTimelineCache ActionTimeline* loadAnimationActionWithContent(const std::string&fileName, const std::string& content); ActionTimeline* createActionWithFlatBuffersFile(const std::string& fileName); - ActionTimeline* createActionWithDataBuffer(cocos2d::Data data, const std::string &fileName); + ActionTimeline* createActionWithDataBuffer(const cocos2d::Data& data, const std::string &fileName); ActionTimeline* loadAnimationActionWithFlatBuffersFile(const std::string& fileName); ActionTimeline* loadAnimationWithDataBuffer(const cocos2d::Data& data, const std::string& fileName); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp index d3368b0fd7e0..9ff74472d984 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.cpp @@ -317,7 +317,7 @@ const cocos2d::Map& SkeletonNode::getAllSubBonesMap() co return _subBonesMap; } -void SkeletonNode::addSkinGroup(std::string groupName, std::map boneSkinNameMap) +void SkeletonNode::addSkinGroup(const std::string& groupName, const std::map& boneSkinNameMap) { _skinGroupMap.emplace(groupName, boneSkinNameMap); } diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.h b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.h index dac5dba72c47..db3b47946191 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCSkeletonNode.h @@ -69,7 +69,7 @@ class CC_STUDIO_DLL SkeletonNode : public BoneNode *@param: groupName, key *@param: boneSkinNameMap, map */ - void addSkinGroup(std::string groupName, std::map boneSkinNameMap); + void addSkinGroup(const std::string& groupName, const std::map& boneSkinNameMap); cocos2d::Rect getBoundingBox() const override; diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index bb98286e0451..f3282de3cf5c 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -211,7 +211,7 @@ Node* SceneReader::nodeByTag(Node *parent, int tag) return _retNode; } -cocos2d::Component* SceneReader::createComponent(const std::string classname) +cocos2d::Component* SceneReader::createComponent(const std::string& classname) { std::string name = this->getComponentClassName(classname); Ref *object = ObjectFactory::getInstance()->createObject(name); diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.h b/cocos/editor-support/cocostudio/CCSSceneReader.h index 092b7ff12d34..857f9c63816a 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.h +++ b/cocos/editor-support/cocostudio/CCSSceneReader.h @@ -73,7 +73,7 @@ class CC_STUDIO_DLL SceneReader private: std::string getComponentClassName(const std::string& name); - cocos2d::Component* createComponent(const std::string classname); + cocos2d::Component* createComponent(const std::string& classname); cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent, AttachComponentType attachComponent); diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 152fe397959a..2fe8be3c26f0 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -325,7 +325,7 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str // NodeTree Offset FlatBuffersSerialize::createNodeTree(const tinyxml2::XMLElement *objectData, - std::string classType) + const std::string& classType) { std::string classname = classType.substr(0, classType.find("ObjectData")); // CCLOG("classname = %s", classname.c_str()); @@ -434,7 +434,7 @@ Offset FlatBuffersSerialize::createNodeTree(const tinyxml2::XMLElement } -int FlatBuffersSerialize::getResourceType(std::string key) +int FlatBuffersSerialize::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { @@ -1410,7 +1410,7 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato } Offset FlatBuffersSerialize::createNodeTreeForSimulator(const tinyxml2::XMLElement *objectData, - std::string classType) + const std::string& classType) { std::string classname = classType.substr(0, classType.find("ObjectData")); // CCLOG("classname = %s", classname.c_str()); diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h index 994eaa268158..87de82219ea8 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h @@ -116,7 +116,7 @@ class CC_STUDIO_DLL FlatBuffersSerialize // NodeTree flatbuffers::Offset createNodeTree(const tinyxml2::XMLElement* objectData, - std::string classType); + const std::string& classType); // NodeAction flatbuffers::Offset createNodeAction(const tinyxml2::XMLElement* objectData); @@ -137,14 +137,14 @@ class CC_STUDIO_DLL FlatBuffersSerialize flatbuffers::Offset createAnimationInfo(const tinyxml2::XMLElement* objectData); /**/ - int getResourceType(std::string key); + int getResourceType(const std::string& key); std::string getGUIClassName(const std::string &name); std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget); /* create flat buffers with XML */ flatbuffers::FlatBufferBuilder* createFlatBuffersWithXMLFileForSimulator(const std::string& xmlFileName); flatbuffers::Offset createNodeTreeForSimulator(const tinyxml2::XMLElement* objectData, - std::string classType); + const std::string& classType); flatbuffers::Offset createProjectNodeOptionsForSimulator(const tinyxml2::XMLElement* objectData); /**/ std::string getCsdVersion() { return _csdVersion; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index b16c00d48fa0..6a7dcd6f69e7 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -967,7 +967,7 @@ namespace cocostudio return button; } - int ButtonReader::getResourceType(std::string key) + int ButtonReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h index 231d811b76d8..454894fd663c 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h @@ -53,7 +53,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* buttonOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* buttonOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp index 85073038f670..bf8aac2fa7fe 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp @@ -440,7 +440,7 @@ namespace cocostudio return node; } - int GameNode3DReader::getResourceType(std::string key) + int GameNode3DReader::getResourceType(const std::string& key) { if (key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.h b/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.h index 1349b882a180..362482be269d 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.h @@ -58,7 +58,7 @@ namespace cocostudio cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* node3DOptions); protected: - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 9139c1a6703f..7df02d8c3dc2 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -422,7 +422,7 @@ namespace cocostudio return imageView; } - int ImageViewReader::getResourceType(std::string key) + int ImageViewReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h index 1af986c85597..4f8479eccd68 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h @@ -53,7 +53,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* imageViewOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* imageViewOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 690e78039741..80d8f1caf870 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -746,7 +746,7 @@ namespace cocostudio return layout; } - int LayoutReader::getResourceType(std::string key) + int LayoutReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h index 8c62f46727a0..3912b2be98e0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h @@ -52,7 +52,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* layoutOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* layoutOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index 9e9c36c4946b..37a05ae0e382 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -609,7 +609,7 @@ namespace cocostudio return listView; } - int ListViewReader::getResourceType(std::string key) + int ListViewReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h index 24b6f769bbb2..6ae3b49788ab 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h @@ -51,7 +51,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* listViewOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* listViewOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index cbf15f8639b6..b0c05c331919 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -355,7 +355,7 @@ namespace cocostudio return loadingBar; } - int LoadingBarReader::getResourceType(std::string key) + int LoadingBarReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h index dcb7ec2344a4..2dcc029f5d3f 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h @@ -51,7 +51,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* loadingBarOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* loadingBarOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp index b8cf93ee0288..5240f88fdd05 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -472,7 +472,7 @@ namespace cocostudio return pageView; } - int PageViewReader::getResourceType(std::string key) + int PageViewReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h index 069c8f2b3e43..8497a6389f08 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h @@ -51,7 +51,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* pageViewOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* pageViewOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index d12971cd9862..f0f3faa059b9 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -591,7 +591,7 @@ namespace cocostudio return scrollView; } - int ScrollViewReader::getResourceType(std::string key) + int ScrollViewReader::getResourceType(const std::string& key) { if (key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h index 26cdf4e73abe..9be9c4abcac3 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h @@ -51,7 +51,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* scrollViewOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* scrollViewOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index 001f57e98285..47fbfe599ec2 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -862,7 +862,7 @@ namespace cocostudio return slider; } - int SliderReader::getResourceType(std::string key) + int SliderReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h index f8bf585a78b8..bae723ce2b9e 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h @@ -51,7 +51,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* sliderOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* sliderOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp index b664d6b12cf9..0db38a5dd10e 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp @@ -273,7 +273,7 @@ namespace cocostudio return sprite; } - int SpriteReader::getResourceType(std::string key) + int SpriteReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.h b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.h index 8d8e9660ef9f..600632b8edba 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.h @@ -51,7 +51,7 @@ namespace cocostudio void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* spriteOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* spriteOptions); - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.cpp index b8c669a9ace2..0352161d855c 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.cpp @@ -902,7 +902,7 @@ cocos2d::Node* TabHeaderReader::createNodeWithFlatBuffers(const flatbuffers::Tab return node; } -int TabHeaderReader::getResourceType(std::string key) +int TabHeaderReader::getResourceType(const std::string& key) { if (key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.h b/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.h index 862a203498e9..8b4204ed4d38 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/TabControlReader/TabControlReader.h @@ -72,7 +72,7 @@ class TabHeaderReader : public cocos2d::Ref, public cocostudio::NodeReaderProtoc cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions) override; private: static TabHeaderReader* _tabheaderReaderInstance; - int getResourceType(std::string key); + int getResourceType(const std::string& key); }; class TabItemReader : public cocos2d::Ref, public cocostudio::NodeReaderProtocol diff --git a/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp index aee7c9da620a..c0fa94fd4ee1 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp @@ -483,7 +483,7 @@ namespace cocostudio return camera; } - int UserCameraReader::getResourceType(std::string key) + int UserCameraReader::getResourceType(const std::string& key) { if (key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.h b/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.h index 5e82f5c624c3..956463f43660 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.h @@ -57,7 +57,7 @@ namespace cocostudio cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* userCameraOptions); protected: - int getResourceType(std::string key); + int getResourceType(const std::string& key); cocos2d::Vec2 getVec2Attribute(const tinyxml2::XMLAttribute* attribute) const; }; } diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index d58480334bb0..da4bb65050b9 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -19069,7 +19069,7 @@ bool js_cocos2dx_FileUtils_getStringFromFile(JSContext *cx, uint32_t argc, jsval { JS::RootedObject jstarget(cx, args.thisv().toObjectOrNull()); std::shared_ptr func(new JSFunctionWrapper(cx, jstarget, args.get(1), args.thisv())); - auto lambda = [=](std::string larg0) -> void { + auto lambda = [=](const std::string& larg0) -> void { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[1]; largv[0] = std_string_to_jsval(cx, larg0); diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp index d6e1e843b5fb..c72acb88442a 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp @@ -6737,7 +6737,7 @@ bool js_cocos2dx_extension_AssetsManagerEx_setVerifyCallback(JSContext *cx, uint { JS::RootedObject jstarget(cx, args.thisv().toObjectOrNull()); std::shared_ptr func(new JSFunctionWrapper(cx, jstarget, args.get(0), args.thisv())); - auto lambda = [=](const std::string& larg0, cocos2d::extension::ManifestAsset larg1) -> bool { + auto lambda = [=](const std::string& larg0, const cocos2d::extension::ManifestAsset& larg1) -> bool { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; largv[0] = std_string_to_jsval(cx, larg0); diff --git a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index b64883208f36..4b2068483dfd 100644 --- a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -156,7 +156,7 @@ class JSB_TableViewDelegate } private: - void callJSDelegate(ScrollView* view, std::string jsFunctionName) + void callJSDelegate(ScrollView* view, const std::string& jsFunctionName) { js_proxy_t * p = jsb_get_native_proxy(view); if (!p) return; @@ -165,7 +165,7 @@ class JSB_TableViewDelegate ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(_JSDelegate), jsFunctionName.c_str(), 1, &arg); } - void callJSDelegate(TableView* table, TableViewCell* cell, std::string jsFunctionName) + void callJSDelegate(TableView* table, TableViewCell* cell, const std::string& jsFunctionName) { js_proxy_t * p = jsb_get_native_proxy(table); if (!p) return; @@ -292,7 +292,7 @@ class JSB_TableViewDataSource } private: - bool callJSDelegate(TableView* table, std::string jsFunctionName, JS::MutableHandleValue retVal) + bool callJSDelegate(TableView* table, const std::string& jsFunctionName, JS::MutableHandleValue retVal) { js_proxy_t * p = jsb_get_native_proxy(table); if (!p) return false; @@ -323,7 +323,7 @@ class JSB_TableViewDataSource return false; } - bool callJSDelegate(TableView* table, ssize_t idx, std::string jsFunctionName, JS::MutableHandleValue retVal) + bool callJSDelegate(TableView* table, ssize_t idx, const std::string& jsFunctionName, JS::MutableHandleValue retVal) { js_proxy_t * p = jsb_get_native_proxy(table); if (!p) return false; diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index fbec4c16cb80..2ec38fa30735 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -379,7 +379,7 @@ void Camera3DTestDemo::onExit() } } -void Camera3DTestDemo::addNewSpriteWithCoords(Vec3 p,std::string fileName,bool playAnimation,float scale,bool bindCamera) +void Camera3DTestDemo::addNewSpriteWithCoords(Vec3 p,const std::string& fileName,bool playAnimation,float scale,bool bindCamera) { auto sprite = Sprite3D::create(fileName); _layer3D->addChild(sprite); diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h index d5ca24f43c53..e213a1241986 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h @@ -106,7 +106,7 @@ class Camera3DTestDemo : public CameraBaseTest virtual void onExit() override; // overrides virtual std::string title() const override; - void addNewSpriteWithCoords(cocos2d::Vec3 p,std::string fileName,bool playAnimation=false,float scale=1.0f,bool bindCamera=false); + void addNewSpriteWithCoords(cocos2d::Vec3 p,const std::string& fileName,bool playAnimation=false,float scale=1.0f,bool bindCamera=false); void onTouchesBegan(const std::vector& touches, cocos2d::Event *event); void onTouchesMoved(const std::vector& touches, cocos2d::Event *event); diff --git a/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp b/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp index 4f4c3c0efe54..cbc6469df371 100644 --- a/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp +++ b/tests/cpp-tests/Classes/ReleasePoolTest/ReleasePoolTest.cpp @@ -36,7 +36,7 @@ class TestObject : public Ref public: TestObject() : _name(""){} - TestObject(std::string name) : _name(name) + TestObject(std::string name) : _name(std::move(name)) { CCLOG("TestObject:%s is created", _name.c_str()); } diff --git a/tests/lua-tests/project/Classes/lua_test_bindings.cpp b/tests/lua-tests/project/Classes/lua_test_bindings.cpp index cce23f87332d..25a0f7fbe217 100644 --- a/tests/lua-tests/project/Classes/lua_test_bindings.cpp +++ b/tests/lua-tests/project/Classes/lua_test_bindings.cpp @@ -323,10 +323,10 @@ void DrawNode3D::setBlendFunc(const BlendFunc &blendFunc) class ValueTypeJudgeInTable:public Node { public: - static ValueTypeJudgeInTable* create(ValueMap valueMap); + static ValueTypeJudgeInTable* create(const ValueMap& valueMap); }; -ValueTypeJudgeInTable* ValueTypeJudgeInTable::create(ValueMap valueMap) +ValueTypeJudgeInTable* ValueTypeJudgeInTable::create(const ValueMap& valueMap) { ValueTypeJudgeInTable* ret = new (std::nothrow) ValueTypeJudgeInTable(); if (ret) From e125daba8a8c12561f0b64e2b19af6bcbe3e55c4 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Thu, 27 Jun 2019 18:04:50 +0800 Subject: [PATCH 2/3] Reference: https://releases.llvm.org/7.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/performance-unnecessary-value-param.html --- .clang-tidy | 2 +- cocos/2d/CCActionInterval.cpp | 6 ++++-- cocos/2d/CCNode.cpp | 6 +++--- cocos/2d/CCNode.h | 6 +++--- cocos/2d/CCRenderTexture.cpp | 10 ++++++---- cocos/2d/CCRenderTexture.h | 4 ++-- cocos/2d/CCTMXXMLParser.cpp | 9 +++++---- cocos/audio/AudioEngine.cpp | 2 +- cocos/audio/include/AudioEngine.h | 2 +- cocos/audio/linux/AudioEngine-linux.cpp | 2 +- cocos/audio/linux/AudioEngine-linux.h | 2 +- cocos/base/ObjectFactory.cpp | 5 +++-- cocos/editor-support/cocosbuilder/CCBReader.cpp | 17 +++++++++-------- .../ActionTimeline/CCActionTimeline.cpp | 16 +++++++++------- .../ActionTimeline/CCActionTimeline.h | 8 ++++---- .../cocostudio/CCArmatureAnimation.cpp | 10 ++++++---- .../editor-support/cocostudio/CCSGUIReader.cpp | 11 ++++++----- .../CheckBoxReader/CheckBoxReader.cpp | 2 +- .../CheckBoxReader/CheckBoxReader.h | 2 +- cocos/network/CCDownloader-curl.cpp | 2 +- cocos/network/SocketIO.cpp | 15 ++++++++------- cocos/physics/CCPhysicsWorld.cpp | 6 +++--- cocos/physics/CCPhysicsWorld.h | 6 +++--- .../js-bindings/manual/network/jsb_socketio.cpp | 4 +++- cocos/ui/UIRichText.cpp | 13 +++++++------ tests/cpp-tests/Classes/BaseTest.cpp | 4 ++-- tests/cpp-tests/Classes/BaseTest.h | 4 ++-- 27 files changed, 96 insertions(+), 80 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9d42e439cd29..c6750db360b4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,7 +10,7 @@ Checks: > performance-move-constructor-init, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, - -performance-unnecessary-value-param, + performance-unnecessary-value-param, readability-container-size-empty, readability-delete-null-pointer, readability-redundant-control-flow, diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index 6cb35ea8a6c8..4f167b0e1b72 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -30,6 +30,8 @@ THE SOFTWARE. #include +#include + #include "2d/CCSprite.h" #include "2d/CCNode.h" #include "2d/CCSpriteFrame.h" @@ -2803,7 +2805,7 @@ void TargetedAction::setForcedTarget(Node* forcedTarget) ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFloatCallback callback) { auto ref = new (std::nothrow) ActionFloat(); - if (ref && ref->initWithDuration(duration, from, to, callback)) + if (ref && ref->initWithDuration(duration, from, to, std::move(callback))) { ref->autorelease(); return ref; @@ -2819,7 +2821,7 @@ bool ActionFloat::initWithDuration(float duration, float from, float to, ActionF { _from = from; _to = to; - _callback = callback; + _callback = std::move(callback); return true; } return false; diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index c8b5d4e06b7a..8aea3820a4ad 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -818,7 +818,7 @@ Node* Node::getChildByName(const std::string& name) const return nullptr; } -void Node::enumerateChildren(const std::string &name, std::function callback) const +void Node::enumerateChildren(const std::string &name, const std::function& callback) const { CCASSERT(!name.empty(), "Invalid name"); CCASSERT(callback != nullptr, "Invalid callback function"); @@ -869,7 +869,7 @@ void Node::enumerateChildren(const std::string &name, std::function callback) const +bool Node::doEnumerateRecursive(const Node* node, const std::string &name, const std::function& callback) const { bool ret =false; @@ -894,7 +894,7 @@ bool Node::doEnumerateRecursive(const Node* node, const std::string &name, std:: return ret; } -bool Node::doEnumerate(std::string name, std::function callback) const +bool Node::doEnumerate(std::string name, const std::function& callback) const { // name may be xxx/yyy, should find its parent size_t pos = name.find('/'); diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 679ce368c4da..111224bfe2ab 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -834,7 +834,7 @@ class CC_DLL Node : public Ref * * @since v3.2 */ - virtual void enumerateChildren(const std::string &name, std::function callback) const; + virtual void enumerateChildren(const std::string &name, const std::function& callback) const; /** * Returns the array of the node's children. * @@ -1886,8 +1886,8 @@ class CC_DLL Node : public Ref virtual void disableCascadeColor(); virtual void updateColor() {} - bool doEnumerate(std::string name, std::function callback) const; - bool doEnumerateRecursive(const Node* node, const std::string &name, std::function callback) const; + bool doEnumerate(std::string name, const std::function& callback) const; + bool doEnumerateRecursive(const Node* node, const std::string &name, const std::function& callback) const; //check whether this camera mask is visible by the current visiting camera bool isVisitableByVisitingCamera() const; diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 3b2b54a5d153..de3e9852a387 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -27,6 +27,8 @@ THE SOFTWARE. #include "2d/CCRenderTexture.h" +#include + #include "base/ccUtils.h" #include "platform/CCFileUtils.h" #include "base/CCEventType.h" @@ -506,7 +508,7 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3 // setOrderOfArrival(0); } -bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA, std::function callback) +bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA, const std::function& callback) { std::string basename(filename); std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower); @@ -528,7 +530,7 @@ bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA, return saveToFileAsNonPMA(filename, Image::Format::JPG, false, callback); } -bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, std::function callback) +bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, const std::function& callback) { std::string basename(filename); std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower); @@ -556,7 +558,7 @@ bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Forma "the image can only be saved as JPG or PNG format"); if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); - _saveFileCallback = callback; + _saveFileCallback = std::move(callback); std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); @@ -572,7 +574,7 @@ bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format "the image can only be saved as JPG or PNG format"); if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); - _saveFileCallback = callback; + _saveFileCallback = std::move(callback); std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 771645501375..fed44de50ac7 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -159,7 +159,7 @@ class CC_DLL RenderTexture : public Node * @param callback When the file is save finished,it will callback this function. * @return Returns true if the operation is successful. */ - bool saveToFileAsNonPMA(const std::string& filename, bool isRGBA = true, std::function callback = nullptr); + bool saveToFileAsNonPMA(const std::string& filename, bool isRGBA = true, const std::function& callback = nullptr); /** Saves the texture into a file using JPEG format. The file will be saved in the Documents folder. @@ -170,7 +170,7 @@ class CC_DLL RenderTexture : public Node * @param callback When the file is save finished,it will callback this function. * @return Returns true if the operation is successful. */ - bool saveToFile(const std::string& filename, bool isRGBA = true, std::function callback = nullptr); + bool saveToFile(const std::string& filename, bool isRGBA = true, const std::function& callback = nullptr); /** saves the texture into a file in non-PMA. The format could be JPG or PNG. The file will be saved in the Documents folder. Returns true if the operation is successful. diff --git a/cocos/2d/CCTMXXMLParser.cpp b/cocos/2d/CCTMXXMLParser.cpp index 9b28910080be..1bc1e96d77d9 100644 --- a/cocos/2d/CCTMXXMLParser.cpp +++ b/cocos/2d/CCTMXXMLParser.cpp @@ -28,13 +28,14 @@ THE SOFTWARE. ****************************************************************************/ #include "2d/CCTMXXMLParser.h" -#include -#include #include "2d/CCTMXTiledMap.h" +#include "base/CCDirector.h" #include "base/ZipUtils.h" #include "base/base64.h" -#include "base/CCDirector.h" #include "platform/CCFileUtils.h" +#include +#include +#include using namespace std; @@ -65,7 +66,7 @@ ValueMap& TMXLayerInfo::getProperties() void TMXLayerInfo::setProperties(ValueMap var) { - _properties = var; + _properties = std::move(var); } // implementation TMXTilesetInfo diff --git a/cocos/audio/AudioEngine.cpp b/cocos/audio/AudioEngine.cpp index f86ac383abe1..2b893f4b509a 100644 --- a/cocos/audio/AudioEngine.cpp +++ b/cocos/audio/AudioEngine.cpp @@ -530,7 +530,7 @@ AudioProfile* AudioEngine::getProfile(const std::string &name) } } -void AudioEngine::preload(const std::string& filePath, std::function callback) +void AudioEngine::preload(const std::string& filePath, const std::function& callback) { if (!isEnabled()) { diff --git a/cocos/audio/include/AudioEngine.h b/cocos/audio/include/AudioEngine.h index 81bd3668a897..5be98e2c1dd2 100644 --- a/cocos/audio/include/AudioEngine.h +++ b/cocos/audio/include/AudioEngine.h @@ -291,7 +291,7 @@ class EXPORT_DLL AudioEngine * @param filePath The file path of an audio. * @param callback A callback which will be called after loading is finished. */ - static void preload(const std::string& filePath, std::function callback); + static void preload(const std::string& filePath, const std::function& callback); /** * Gets playing audio count. diff --git a/cocos/audio/linux/AudioEngine-linux.cpp b/cocos/audio/linux/AudioEngine-linux.cpp index 83e3fb401c2d..a51f13e298c8 100644 --- a/cocos/audio/linux/AudioEngine-linux.cpp +++ b/cocos/audio/linux/AudioEngine-linux.cpp @@ -301,7 +301,7 @@ void AudioEngineImpl::uncacheAll() mapId.clear(); } -int AudioEngineImpl::preload(const std::string& filePath, std::function callback) +int AudioEngineImpl::preload(const std::string& filePath, const std::function& callback) { FMOD::Sound * sound = findSound(filePath); if (!sound) { diff --git a/cocos/audio/linux/AudioEngine-linux.h b/cocos/audio/linux/AudioEngine-linux.h index d52a152e5b89..272af7d70f02 100644 --- a/cocos/audio/linux/AudioEngine-linux.h +++ b/cocos/audio/linux/AudioEngine-linux.h @@ -65,7 +65,7 @@ class CC_DLL AudioEngineImpl : public cocos2d::Ref void uncacheAll(); - int preload(const std::string& filePath, std::function callback); + int preload(const std::string& filePath, const std::function& callback); void update(float dt); diff --git a/cocos/base/ObjectFactory.cpp b/cocos/base/ObjectFactory.cpp index 1bc2ad5c0ab3..ace28b2060dc 100644 --- a/cocos/base/ObjectFactory.cpp +++ b/cocos/base/ObjectFactory.cpp @@ -23,8 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include #include "base/ObjectFactory.h" +#include +#include NS_CC_BEGIN @@ -47,7 +48,7 @@ ObjectFactory::TInfo::TInfo(const std::string& type, Instance ins) ObjectFactory::TInfo::TInfo(const std::string& type, InstanceFunc ins) :_class(type) ,_fun(nullptr) - ,_func(ins) + ,_func(std::move(ins)) { ObjectFactory::getInstance()->registerType(*this); } diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index 5b5eb2a3f562..ce05782eeda6 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -31,16 +31,17 @@ #include "2d/CCSpriteFrameCache.h" #include "renderer/CCTextureCache.h" +#include "editor-support/cocosbuilder/CCBAnimationManager.h" +#include "editor-support/cocosbuilder/CCBKeyframe.h" +#include "editor-support/cocosbuilder/CCBMemberVariableAssigner.h" #include "editor-support/cocosbuilder/CCBReader.h" +#include "editor-support/cocosbuilder/CCBSelectorResolver.h" +#include "editor-support/cocosbuilder/CCBSequenceProperty.h" #include "editor-support/cocosbuilder/CCNodeLoader.h" #include "editor-support/cocosbuilder/CCNodeLoaderLibrary.h" #include "editor-support/cocosbuilder/CCNodeLoaderListener.h" -#include "editor-support/cocosbuilder/CCBMemberVariableAssigner.h" -#include "editor-support/cocosbuilder/CCBSelectorResolver.h" -#include "editor-support/cocosbuilder/CCBAnimationManager.h" -#include "editor-support/cocosbuilder/CCBSequenceProperty.h" -#include "editor-support/cocosbuilder/CCBKeyframe.h" #include +#include using namespace cocos2d; using namespace cocos2d::extension; @@ -193,7 +194,7 @@ CCBReader::CCBAnimationManagerMapPtr CCBReader::getAnimationManagers() void CCBReader::setAnimationManagers(CCBAnimationManagerMapPtr x) { - _animationManagers = x; + _animationManagers = std::move(x); } CCBMemberVariableAssigner * CCBReader::getCCBMemberVariableAssigner() { @@ -255,7 +256,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Ref *pOwner, co Node* CCBReader::readNodeGraphFromData(std::shared_ptr data, Ref *pOwner, const Size &parentSize) { - _data = data; + _data = std::move(data); _bytes =_data->getBytes(); _currentByte = 0; _currentBit = 0; @@ -337,7 +338,7 @@ Node* CCBReader::readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am return nullptr; } - setAnimationManagers(am); + setAnimationManagers(std::move(am)); Node *pNode = readNodeGraph(nullptr); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp index 8c56602d40e6..4a7ea1fb5952 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp @@ -25,6 +25,8 @@ THE SOFTWARE. #include "editor-support/cocostudio/ActionTimeline/CCActionTimeline.h" +#include + #include "editor-support/cocostudio/CCComExtensionData.h" USING_NS_CC; @@ -94,7 +96,7 @@ bool ActionTimeline::init() return true; } -void ActionTimeline::play(std::string name, bool loop) +void ActionTimeline::play(const std::string& name, bool loop) { if (_animationInfos.find(name) == _animationInfos.end()) { @@ -233,7 +235,7 @@ void ActionTimeline::step(float delta) } typedef std::function tCallBack; -void foreachNodeDescendant(Node* parent, tCallBack callback) +void foreachNodeDescendant(Node* parent, const tCallBack& callback) { callback(parent); @@ -312,7 +314,7 @@ void ActionTimeline::addAnimationInfo(const AnimationInfo& animationInfo) addFrameEndCallFunc(animationInfo.endIndex, animationInfo.name, animationInfo.clipEndCallBack); } -void ActionTimeline::removeAnimationInfo(std::string animationName) +void ActionTimeline::removeAnimationInfo(const std::string& animationName) { auto clipIter = _animationInfos.find(animationName); if (clipIter == _animationInfos.end()) @@ -335,7 +337,7 @@ const AnimationInfo& ActionTimeline::getAnimationInfo(const std::string &animati return _animationInfos.find(animationName)->second; } -void ActionTimeline::setAnimationEndCallFunc(const std::string animationName, std::function func) +void ActionTimeline::setAnimationEndCallFunc(const std::string& animationName, const std::function& func) { auto clipIter = _animationInfos.find(animationName); if (clipIter == _animationInfos.end()) @@ -349,7 +351,7 @@ void ActionTimeline::setAnimationEndCallFunc(const std::string animationName, st void ActionTimeline::setFrameEventCallFunc(std::function listener) { - _frameEventListener = listener; + _frameEventListener = std::move(listener); } void ActionTimeline::clearFrameEventCallFunc() @@ -359,7 +361,7 @@ void ActionTimeline::clearFrameEventCallFunc() void ActionTimeline::setLastFrameCallFunc(std::function listener) { - _lastFrameListener = listener; + _lastFrameListener = std::move(listener); } void ActionTimeline::clearLastFrameCallFunc() @@ -375,7 +377,7 @@ void ActionTimeline::emitFrameEvent(Frame* frame) } } -void ActionTimeline::addFrameEndCallFunc(int frameIndex, const std::string& funcKey, std::function func) +void ActionTimeline::addFrameEndCallFunc(int frameIndex, const std::string& funcKey, const std::function& func) { if (func != nullptr) { diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h index 04182d2003d7..b23fe7223330 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h @@ -82,7 +82,7 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action, public cocos2d::Pla ActionTimeline(); virtual ~ActionTimeline(); - virtual void play(std::string animationName, bool loop); + virtual void play(const std::string& animationName, bool loop); virtual bool init(); @@ -155,14 +155,14 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action, public cocos2d::Pla /** AnimationInfo*/ virtual void addAnimationInfo(const AnimationInfo& animationInfo); - virtual void removeAnimationInfo(std::string animationName); + virtual void removeAnimationInfo(const std::string& animationName); virtual bool IsAnimationInfoExists(const std::string& animationName); virtual const AnimationInfo& getAnimationInfo(const std::string& animationName); /**add a frame end call back to animation's end frame * @param animationName @addFrameEndCallFunc, make the animationName as funcKey * @param func the callback function */ - virtual void setAnimationEndCallFunc(const std::string animationName, std::function func); + virtual void setAnimationEndCallFunc(const std::string& animationName, const std::function& func); /** Set ActionTimeline's frame event callback function */ void setFrameEventCallFunc(std::function listener); @@ -177,7 +177,7 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action, public cocos2d::Pla * @param funcKey for identity the callback function * @param func the callback function */ - virtual void addFrameEndCallFunc(int frameIndex, const std::string& funcKey, std::function func); + virtual void addFrameEndCallFunc(int frameIndex, const std::string& funcKey, const std::function& func); // remove callback function after frameIndex which identified with funcKey virtual void removeFrameEndCallFunc(int frameIndex, const std::string& funcKey); // clear callback functions after frameIndex diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp index 162bf7935033..16caad745dd9 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp @@ -24,11 +24,13 @@ THE SOFTWARE. ****************************************************************************/ #include "editor-support/cocostudio/CCArmatureAnimation.h" + #include "editor-support/cocostudio/CCArmature.h" -#include "editor-support/cocostudio/CCBone.h" #include "editor-support/cocostudio/CCArmatureDefine.h" -#include "editor-support/cocostudio/CCUtilMath.h" +#include "editor-support/cocostudio/CCBone.h" #include "editor-support/cocostudio/CCDatas.h" +#include "editor-support/cocostudio/CCUtilMath.h" +#include using namespace cocos2d; @@ -484,11 +486,11 @@ void ArmatureAnimation::setFrameEventCallFunc(Ref *target, SEL_FrameEventCallFun void ArmatureAnimation::setMovementEventCallFunc(std::function listener) { - _movementEventListener = listener; + _movementEventListener = std::move(listener); } void ArmatureAnimation::setFrameEventCallFunc(std::function listener) { - _frameEventListener = listener; + _frameEventListener = std::move(listener); } void ArmatureAnimation::setUserObject(Ref *pUserObject) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index b98b66bdd14d..4b5680411606 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -24,13 +24,14 @@ THE SOFTWARE. ****************************************************************************/ #include "editor-support/cocostudio/CCSGUIReader.h" -#include -#include -#include "ui/CocosGUI.h" -#include "platform/CCFileUtils.h" #include "2d/CCSpriteFrameCache.h" #include "base/CCDirector.h" #include "base/ccUtils.h" +#include "platform/CCFileUtils.h" +#include "ui/CocosGUI.h" +#include +#include +#include #include "editor-support/cocostudio/CCActionManagerEx.h" #include "editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h" @@ -192,7 +193,7 @@ void GUIReader::registerTypeAndCallBack(const std::string& classType, { ObjectFactory* factoryCreate = ObjectFactory::getInstance(); - ObjectFactory::TInfo t(classType, ins); + ObjectFactory::TInfo t(classType, std::move(ins)); factoryCreate->registerType(t); if (object) diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 7a1bf1acb61b..08e820e5af1d 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -775,7 +775,7 @@ namespace cocostudio return checkBox; } - int CheckBoxReader::getResourceType(std::string key) + int CheckBoxReader::getResourceType(const std::string& key) { if(key == "Normal" || key == "Default") { diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h index d1a3ccd61b9e..0cebc7633951 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h @@ -50,7 +50,7 @@ namespace cocostudio flatbuffers::FlatBufferBuilder* builder); void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* checkBoxOptions); cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* checkBoxOptions); - virtual int getResourceType(std::string key); + virtual int getResourceType(const std::string& key); }; } diff --git a/cocos/network/CCDownloader-curl.cpp b/cocos/network/CCDownloader-curl.cpp index caf02212c511..fbfc8173907a 100644 --- a/cocos/network/CCDownloader-curl.cpp +++ b/cocos/network/CCDownloader-curl.cpp @@ -256,7 +256,7 @@ namespace cocos2d { namespace network { DLLOG("Destruct DownloaderCURL::Impl %p %d", this, _thread.joinable()); } - void addTask(std::shared_ptr task, DownloadTaskCURL* coTask) + void addTask(const std::shared_ptr& task, DownloadTaskCURL* coTask) { if (DownloadTask::ERROR_NO_ERROR == coTask->_errCode) { diff --git a/cocos/network/SocketIO.cpp b/cocos/network/SocketIO.cpp index 6fca951989cc..520adb0f67cf 100644 --- a/cocos/network/SocketIO.cpp +++ b/cocos/network/SocketIO.cpp @@ -29,15 +29,16 @@ ****************************************************************************/ #include "network/SocketIO.h" -#include "network/Uri.h" -#include -#include -#include -#include "base/ccUTF8.h" #include "base/CCDirector.h" #include "base/CCScheduler.h" -#include "network/WebSocket.h" +#include "base/ccUTF8.h" #include "network/HttpClient.h" +#include "network/Uri.h" +#include "network/WebSocket.h" +#include +#include +#include +#include #include "json/rapidjson.h" #include "json/document-wrapper.h" @@ -1131,7 +1132,7 @@ void SIOClient::setConnected(bool connected) void SIOClient::on(const std::string& eventName, SIOEvent e) { - _eventRegistry[eventName] = e; + _eventRegistry[eventName] = std::move(e); } void SIOClient::fireEvent(const std::string& eventName, const std::string& data) diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index cd6effd739f2..62c4e3c39d99 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -395,7 +395,7 @@ void PhysicsWorld::collisionSeparateCallback(PhysicsContact& contact) _eventDispatcher->dispatchEvent(&contact); } -void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1, const Vec2& point2, void* data) +void PhysicsWorld::rayCast(const PhysicsRayCastCallbackFunc& func, const Vec2& point1, const Vec2& point2, void* data) { CCASSERT(func != nullptr, "func shouldn't be nullptr"); @@ -418,7 +418,7 @@ void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1, } } -void PhysicsWorld::queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect, void* data) +void PhysicsWorld::queryRect(const PhysicsQueryRectCallbackFunc& func, const Rect& rect, void* data) { CCASSERT(func != nullptr, "func shouldn't be nullptr"); @@ -439,7 +439,7 @@ void PhysicsWorld::queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect } } -void PhysicsWorld::queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& point, void* data) +void PhysicsWorld::queryPoint(const PhysicsQueryPointCallbackFunc& func, const Vec2& point, void* data) { CCASSERT(func != nullptr, "func shouldn't be nullptr"); diff --git a/cocos/physics/CCPhysicsWorld.h b/cocos/physics/CCPhysicsWorld.h index e6cb026327b5..4dc019e863bb 100644 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -167,7 +167,7 @@ class CC_DLL PhysicsWorld * @param end A Vec2 object contains the end position of the ray. * @param data User defined data, it is passed to func. */ - void rayCast(PhysicsRayCastCallbackFunc func, const Vec2& start, const Vec2& end, void* data); + void rayCast(const PhysicsRayCastCallbackFunc& func, const Vec2& start, const Vec2& end, void* data); /** * Searches for physics shapes that contains in the rect. @@ -177,7 +177,7 @@ class CC_DLL PhysicsWorld * @param rect A Rect object contains a rectangle's x, y, width and height. * @param data User defined data, it is passed to func. */ - void queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect, void* data); + void queryRect(const PhysicsQueryRectCallbackFunc& func, const Rect& rect, void* data); /** * Searches for physics shapes that contains the point. @@ -187,7 +187,7 @@ class CC_DLL PhysicsWorld * @param point A Vec2 object contains the position of the point. * @param data User defined data, it is passed to func. */ - void queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& point, void* data); + void queryPoint(const PhysicsQueryPointCallbackFunc& func, const Vec2& point, void* data); /** * Get physics shapes that contains the point. diff --git a/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp b/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp index 5495556b15d6..675aa0580065 100644 --- a/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp +++ b/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp @@ -23,7 +23,9 @@ */ #include "scripting/js-bindings/manual/network/jsb_socketio.h" + #include "scripting/js-bindings/manual/jsb_helper.h" +#include #include "network/WebSocket.h" #include "network/SocketIO.h" @@ -116,7 +118,7 @@ class JSB_SocketIODelegate : public SocketIO::SIODelegate void addEvent(const std::string& eventName, std::shared_ptr callback) { - _eventRegistry[eventName] = callback; + _eventRegistry[eventName] = std::move(callback); } private: diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index f63e93c2e03d..1d2969aaa206 100755 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -25,10 +25,11 @@ #include "ui/UIRichText.h" +#include +#include #include +#include #include -#include -#include #include "platform/CCFileUtils.h" #include "platform/CCApplication.h" @@ -50,14 +51,14 @@ class ListenerComponent : public Component public: static const std::string COMPONENT_NAME; /*!< component name */ - static ListenerComponent* create(Node* parent, const std::string& url, const RichText::OpenUrlHandler handleOpenUrl = nullptr) + static ListenerComponent* create(Node* parent, const std::string& url, const RichText::OpenUrlHandler& handleOpenUrl = nullptr) { auto component = new (std::nothrow) ListenerComponent(parent, url, handleOpenUrl); component->autorelease(); return component; } - explicit ListenerComponent(Node* parent, const std::string& url, const RichText::OpenUrlHandler handleOpenUrl) + explicit ListenerComponent(Node* parent, const std::string& url, const RichText::OpenUrlHandler& handleOpenUrl) : _parent(parent) , _url(url) , _handleOpenUrl(handleOpenUrl) @@ -822,7 +823,7 @@ void MyXMLVisitor::pushBackElement(RichElement* element) void MyXMLVisitor::setTagDescription(const std::string& tag, bool isFontElement, RichText::VisitEnterHandler handleVisitEnter) { - MyXMLVisitor::_tagTables[tag] = {isFontElement, handleVisitEnter}; + MyXMLVisitor::_tagTables[tag] = {isFontElement, std::move(handleVisitEnter)}; } void MyXMLVisitor::removeTagDescription(const std::string& tag) @@ -1327,7 +1328,7 @@ std::string RichText::stringWithColor4B(const cocos2d::Color4B& color4b) void RichText::setTagDescription(const std::string& tag, bool isFontElement, VisitEnterHandler handleVisitEnter) { - MyXMLVisitor::setTagDescription(tag, isFontElement, handleVisitEnter); + MyXMLVisitor::setTagDescription(tag, isFontElement, std::move(handleVisitEnter)); } void RichText::removeTagDescription(const std::string& tag) diff --git a/tests/cpp-tests/Classes/BaseTest.cpp b/tests/cpp-tests/Classes/BaseTest.cpp index 9000a5c9418c..8e568adbcdbf 100644 --- a/tests/cpp-tests/Classes/BaseTest.cpp +++ b/tests/cpp-tests/Classes/BaseTest.cpp @@ -132,7 +132,7 @@ TestList::TestList() _shouldRestoreTableOffset = false; } -void TestList::addTest(const std::string& testName, std::function callback) +void TestList::addTest(const std::string& testName, const std::function& callback) { if (!testName.empty()) { @@ -256,7 +256,7 @@ ssize_t TestList::numberOfCellsInTableView(TableView *table) } //TestSuite -void TestSuite::addTestCase(const std::string& testName, std::function callback) +void TestSuite::addTestCase(const std::string& testName, const std::function& callback) { if (!testName.empty() && callback) { diff --git a/tests/cpp-tests/Classes/BaseTest.h b/tests/cpp-tests/Classes/BaseTest.h index 86237bb2e378..9f2a862185cd 100644 --- a/tests/cpp-tests/Classes/BaseTest.h +++ b/tests/cpp-tests/Classes/BaseTest.h @@ -157,7 +157,7 @@ class TestController; class TestSuite : public TestBase { public: - void addTestCase(const std::string& testName, std::function callback); + void addTestCase(const std::string& testName, const std::function& callback); virtual void restartCurrTest(); virtual void enterNextTest(); @@ -181,7 +181,7 @@ class TestList : public TestBase, public cocos2d::extension::TableViewDataSource public: TestList(); - void addTest(const std::string& testName, std::function callback); + void addTest(const std::string& testName, const std::function& callback); virtual void runThisTest() override; From 5308da4b06d0705e1ff98619e0efd3592dd92d74 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Tue, 2 Jul 2019 13:47:14 +0800 Subject: [PATCH 3/3] perfer pass by const reference If a object is passed by value and moved to new value. Prefer passing it by reference and copy it, if allowed. --- cocos/2d/CCActionInterval.cpp | 8 ++++---- cocos/2d/CCActionInterval.h | 4 ++-- cocos/2d/CCRenderTexture.cpp | 8 ++++---- cocos/2d/CCRenderTexture.h | 4 ++-- cocos/2d/CCTMXXMLParser.cpp | 4 ++-- cocos/2d/CCTMXXMLParser.h | 2 +- cocos/base/ObjectFactory.cpp | 4 ++-- cocos/base/ObjectFactory.h | 2 +- cocos/editor-support/cocosbuilder/CCBReader.cpp | 8 ++++---- cocos/editor-support/cocosbuilder/CCBReader.h | 4 ++-- .../cocostudio/ActionTimeline/CCActionTimeline.cpp | 8 ++++---- .../cocostudio/ActionTimeline/CCActionTimeline.h | 4 ++-- .../editor-support/cocostudio/CCArmatureAnimation.cpp | 8 ++++---- cocos/editor-support/cocostudio/CCArmatureAnimation.h | 4 ++-- cocos/editor-support/cocostudio/CCSGUIReader.cpp | 4 ++-- cocos/editor-support/cocostudio/CCSGUIReader.h | 2 +- cocos/network/SocketIO.cpp | 4 ++-- cocos/network/SocketIO.h | 2 +- cocos/ui/UIRichText.cpp | 10 +++++----- cocos/ui/UIRichText.h | 2 +- 20 files changed, 48 insertions(+), 48 deletions(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index 4f167b0e1b72..dd175876a83f 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -2802,10 +2802,10 @@ void TargetedAction::setForcedTarget(Node* forcedTarget) // ActionFloat -ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFloatCallback callback) +ActionFloat* ActionFloat::create(float duration, float from, float to, const ActionFloatCallback& callback) { auto ref = new (std::nothrow) ActionFloat(); - if (ref && ref->initWithDuration(duration, from, to, std::move(callback))) + if (ref && ref->initWithDuration(duration, from, to, callback)) { ref->autorelease(); return ref; @@ -2815,13 +2815,13 @@ ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFlo return nullptr; } -bool ActionFloat::initWithDuration(float duration, float from, float to, ActionFloatCallback callback) +bool ActionFloat::initWithDuration(float duration, float from, float to, const ActionFloatCallback& callback) { if (ActionInterval::initWithDuration(duration)) { _from = from; _to = to; - _callback = std::move(callback); + _callback = callback; return true; } return false; diff --git a/cocos/2d/CCActionInterval.h b/cocos/2d/CCActionInterval.h index 7870375d304e..d327d37032f9 100644 --- a/cocos/2d/CCActionInterval.h +++ b/cocos/2d/CCActionInterval.h @@ -1650,7 +1650,7 @@ class CC_DLL ActionFloat : public ActionInterval * * @return An autoreleased ActionFloat object */ - static ActionFloat* create(float duration, float from, float to, ActionFloatCallback callback); + static ActionFloat* create(float duration, float from, float to, const ActionFloatCallback& callback); /** * Overridden ActionInterval methods @@ -1664,7 +1664,7 @@ class CC_DLL ActionFloat : public ActionInterval ActionFloat() {}; virtual ~ActionFloat() {}; - bool initWithDuration(float duration, float from, float to, ActionFloatCallback callback); + bool initWithDuration(float duration, float from, float to, const ActionFloatCallback& callback); protected: /* From value */ diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index de3e9852a387..fc6ff53f44a8 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -552,13 +552,13 @@ bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, const s return saveToFile(filename, Image::Format::JPG, false, callback); } -bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback) +bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, const std::function& callback) { CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, "the image can only be saved as JPG or PNG format"); if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); - _saveFileCallback = std::move(callback); + _saveFileCallback = callback; std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); @@ -568,13 +568,13 @@ bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Forma return true; } -bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback) +bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, const std::function& callback) { CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, "the image can only be saved as JPG or PNG format"); if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); - _saveFileCallback = std::move(callback); + _saveFileCallback = callback; std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index fed44de50ac7..83591dd24b83 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -184,7 +184,7 @@ class CC_DLL RenderTexture : public Node * @param callback When the file is save finished,it will callback this function. * @return Returns true if the operation is successful. */ - bool saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback); + bool saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, const std::function& callback); /** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder. Returns true if the operation is successful. @@ -198,7 +198,7 @@ class CC_DLL RenderTexture : public Node * @param callback When the file is save finished,it will callback this function. * @return Returns true if the operation is successful. */ - bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, std::function callback = nullptr); + bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, const std::function& callback = nullptr); /** Listen "come to background" message, and save render texture. * It only has effect on Android. diff --git a/cocos/2d/CCTMXXMLParser.cpp b/cocos/2d/CCTMXXMLParser.cpp index 1bc1e96d77d9..3393461378ca 100644 --- a/cocos/2d/CCTMXXMLParser.cpp +++ b/cocos/2d/CCTMXXMLParser.cpp @@ -64,9 +64,9 @@ ValueMap& TMXLayerInfo::getProperties() return _properties; } -void TMXLayerInfo::setProperties(ValueMap var) +void TMXLayerInfo::setProperties(const ValueMap& var) { - _properties = std::move(var); + _properties = var; } // implementation TMXTilesetInfo diff --git a/cocos/2d/CCTMXXMLParser.h b/cocos/2d/CCTMXXMLParser.h index b7ff1536b029..6e60f8071e16 100644 --- a/cocos/2d/CCTMXXMLParser.h +++ b/cocos/2d/CCTMXXMLParser.h @@ -106,7 +106,7 @@ class CC_DLL TMXLayerInfo : public Ref */ virtual ~TMXLayerInfo(); - void setProperties(ValueMap properties); + void setProperties(const ValueMap& properties); ValueMap& getProperties(); ValueMap _properties; diff --git a/cocos/base/ObjectFactory.cpp b/cocos/base/ObjectFactory.cpp index ace28b2060dc..8dbc16e48d5e 100644 --- a/cocos/base/ObjectFactory.cpp +++ b/cocos/base/ObjectFactory.cpp @@ -45,10 +45,10 @@ ObjectFactory::TInfo::TInfo(const std::string& type, Instance ins) ObjectFactory::getInstance()->registerType(*this); } -ObjectFactory::TInfo::TInfo(const std::string& type, InstanceFunc ins) +ObjectFactory::TInfo::TInfo(const std::string& type, const InstanceFunc& ins) :_class(type) ,_fun(nullptr) - ,_func(std::move(ins)) + ,_func(ins) { ObjectFactory::getInstance()->registerType(*this); } diff --git a/cocos/base/ObjectFactory.h b/cocos/base/ObjectFactory.h index c1cf3f7842a8..4ae1b6f84149 100644 --- a/cocos/base/ObjectFactory.h +++ b/cocos/base/ObjectFactory.h @@ -43,7 +43,7 @@ class CC_DLL ObjectFactory { TInfo(); TInfo(const std::string& type, Instance ins = nullptr); - TInfo(const std::string& type, InstanceFunc ins = nullptr); + TInfo(const std::string& type, const InstanceFunc& ins = nullptr); TInfo(const TInfo &t); ~TInfo(); TInfo& operator= (const TInfo &t); diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index ce05782eeda6..32492ad73c2c 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -192,9 +192,9 @@ CCBReader::CCBAnimationManagerMapPtr CCBReader::getAnimationManagers() return _animationManagers; } -void CCBReader::setAnimationManagers(CCBAnimationManagerMapPtr x) +void CCBReader::setAnimationManagers(const CCBAnimationManagerMapPtr& x) { - _animationManagers = std::move(x); + _animationManagers = x; } CCBMemberVariableAssigner * CCBReader::getCCBMemberVariableAssigner() { @@ -321,7 +321,7 @@ void CCBReader::cleanUpNodeGraph(Node *node) } } -Node* CCBReader::readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am) +Node* CCBReader::readFileWithCleanUp(bool bCleanUp, const CCBAnimationManagerMapPtr& am) { if (! readHeader()) { @@ -338,7 +338,7 @@ Node* CCBReader::readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am return nullptr; } - setAnimationManagers(std::move(am)); + setAnimationManagers(am); Node *pNode = readNodeGraph(nullptr); diff --git a/cocos/editor-support/cocosbuilder/CCBReader.h b/cocos/editor-support/cocosbuilder/CCBReader.h index 02f55f83cec6..e2de7b0717c5 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.h +++ b/cocos/editor-support/cocosbuilder/CCBReader.h @@ -337,7 +337,7 @@ class CC_DLL CCBReader : public cocos2d::Ref * @js NA * @lua NA */ - void setAnimationManagers(CCBAnimationManagerMapPtr x); + void setAnimationManagers(const CCBAnimationManagerMapPtr& x); /** * @js NA * @lua NA @@ -370,7 +370,7 @@ class CC_DLL CCBReader : public cocos2d::Ref * @js NA * @lua NA */ - cocos2d::Node* readFileWithCleanUp(bool bCleanUp, CCBAnimationManagerMapPtr am); + cocos2d::Node* readFileWithCleanUp(bool bCleanUp, const CCBAnimationManagerMapPtr& am); void addOwnerOutletName(const std::string& name); void addOwnerOutletNode(cocos2d::Node *node); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp index 4a7ea1fb5952..46f8ecfad138 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp @@ -349,9 +349,9 @@ void ActionTimeline::setAnimationEndCallFunc(const std::string& animationName, c addFrameEndCallFunc(clipIter->second.endIndex, animationName, func); } -void ActionTimeline::setFrameEventCallFunc(std::function listener) +void ActionTimeline::setFrameEventCallFunc(const std::function& listener) { - _frameEventListener = std::move(listener); + _frameEventListener = listener; } void ActionTimeline::clearFrameEventCallFunc() @@ -359,9 +359,9 @@ void ActionTimeline::clearFrameEventCallFunc() _frameEventListener = nullptr; } -void ActionTimeline::setLastFrameCallFunc(std::function listener) +void ActionTimeline::setLastFrameCallFunc(const std::function& listener) { - _lastFrameListener = std::move(listener); + _lastFrameListener = listener; } void ActionTimeline::clearLastFrameCallFunc() diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h index b23fe7223330..fb7376ce2559 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h @@ -165,11 +165,11 @@ class CC_STUDIO_DLL ActionTimeline : public cocos2d::Action, public cocos2d::Pla virtual void setAnimationEndCallFunc(const std::string& animationName, const std::function& func); /** Set ActionTimeline's frame event callback function */ - void setFrameEventCallFunc(std::function listener); + void setFrameEventCallFunc(const std::function& listener); void clearFrameEventCallFunc(); /** Last frame callback will call when arriving last frame */ - void setLastFrameCallFunc(std::function listener); + void setLastFrameCallFunc(const std::function& listener); void clearLastFrameCallFunc(); /** add a callback function after played frameIndex diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp index 16caad745dd9..b37e4b9a5cf3 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.cpp @@ -484,13 +484,13 @@ void ArmatureAnimation::setFrameEventCallFunc(Ref *target, SEL_FrameEventCallFun _frameEventCallFunc = callFunc; } -void ArmatureAnimation::setMovementEventCallFunc(std::function listener) +void ArmatureAnimation::setMovementEventCallFunc(const std::function& listener) { - _movementEventListener = std::move(listener); + _movementEventListener = listener; } -void ArmatureAnimation::setFrameEventCallFunc(std::function listener) +void ArmatureAnimation::setFrameEventCallFunc(const std::function& listener) { - _frameEventListener = std::move(listener); + _frameEventListener = listener; } void ArmatureAnimation::setUserObject(Ref *pUserObject) diff --git a/cocos/editor-support/cocostudio/CCArmatureAnimation.h b/cocos/editor-support/cocostudio/CCArmatureAnimation.h index 43de286d21d4..3eb39dad4985 100644 --- a/cocos/editor-support/cocostudio/CCArmatureAnimation.h +++ b/cocos/editor-support/cocostudio/CCArmatureAnimation.h @@ -194,8 +194,8 @@ class CC_STUDIO_DLL ArmatureAnimation : public ProcessBase */ CC_DEPRECATED_ATTRIBUTE void setFrameEventCallFunc(cocos2d::Ref *target, SEL_FrameEventCallFunc callFunc); - void setMovementEventCallFunc(std::function listener); - void setFrameEventCallFunc(std::function listener); + void setMovementEventCallFunc(const std::function& listener); + void setFrameEventCallFunc(const std::function& listener); virtual void setAnimationData(AnimationData *data) { diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 4b5680411606..73afa4fcd744 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -187,13 +187,13 @@ void GUIReader::registerTypeAndCallBack(const std::string& classType, } void GUIReader::registerTypeAndCallBack(const std::string& classType, - ObjectFactory::InstanceFunc ins, + const ObjectFactory::InstanceFunc& ins, Ref *object, SEL_ParseEvent callBack) { ObjectFactory* factoryCreate = ObjectFactory::getInstance(); - ObjectFactory::TInfo t(classType, std::move(ins)); + ObjectFactory::TInfo t(classType, ins); factoryCreate->registerType(t); if (object) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.h b/cocos/editor-support/cocostudio/CCSGUIReader.h index 8c64dc0970af..024ba838e7a4 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.h +++ b/cocos/editor-support/cocostudio/CCSGUIReader.h @@ -86,7 +86,7 @@ class CC_STUDIO_DLL GUIReader : public cocos2d::Ref SEL_ParseEvent callBack); void registerTypeAndCallBack(const std::string& classType, - cocos2d::ObjectFactory::InstanceFunc ins, + const cocos2d::ObjectFactory::InstanceFunc& ins, Ref* object, SEL_ParseEvent callBack); protected: diff --git a/cocos/network/SocketIO.cpp b/cocos/network/SocketIO.cpp index 520adb0f67cf..ee995da38082 100644 --- a/cocos/network/SocketIO.cpp +++ b/cocos/network/SocketIO.cpp @@ -1130,9 +1130,9 @@ void SIOClient::setConnected(bool connected) _connected = connected; } -void SIOClient::on(const std::string& eventName, SIOEvent e) +void SIOClient::on(const std::string& eventName, const SIOEvent& e) { - _eventRegistry[eventName] = std::move(e); + _eventRegistry[eventName] = e; } void SIOClient::fireEvent(const std::string& eventName, const std::string& data) diff --git a/cocos/network/SocketIO.h b/cocos/network/SocketIO.h index 50e7a5cce1e8..52957acb0a35 100644 --- a/cocos/network/SocketIO.h +++ b/cocos/network/SocketIO.h @@ -276,7 +276,7 @@ class CC_DLL SIOClient * @param eventName the name of event. * @param e the callback function. */ - void on(const std::string& eventName, SIOEvent e); + void on(const std::string& eventName, const SIOEvent& e); /** * Set tag of SIOClient. diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index 1d2969aaa206..a7931a248eff 100755 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -347,7 +347,7 @@ class MyXMLVisitor : public SAXDelegator void pushBackElement(RichElement* element); - static void setTagDescription(const std::string& tag, bool isFontElement, RichText::VisitEnterHandler handleVisitEnter); + static void setTagDescription(const std::string& tag, bool isFontElement, const RichText::VisitEnterHandler& handleVisitEnter); static void removeTagDescription(const std::string& tag); @@ -821,9 +821,9 @@ void MyXMLVisitor::pushBackElement(RichElement* element) _richText->pushBackElement(element); } -void MyXMLVisitor::setTagDescription(const std::string& tag, bool isFontElement, RichText::VisitEnterHandler handleVisitEnter) +void MyXMLVisitor::setTagDescription(const std::string& tag, bool isFontElement, const RichText::VisitEnterHandler& handleVisitEnter) { - MyXMLVisitor::_tagTables[tag] = {isFontElement, std::move(handleVisitEnter)}; + MyXMLVisitor::_tagTables[tag] = {isFontElement, handleVisitEnter}; } void MyXMLVisitor::removeTagDescription(const std::string& tag) @@ -1326,9 +1326,9 @@ std::string RichText::stringWithColor4B(const cocos2d::Color4B& color4b) return std::string(buf, 9); } -void RichText::setTagDescription(const std::string& tag, bool isFontElement, VisitEnterHandler handleVisitEnter) +void RichText::setTagDescription(const std::string& tag, bool isFontElement, const VisitEnterHandler& handleVisitEnter) { - MyXMLVisitor::setTagDescription(tag, isFontElement, std::move(handleVisitEnter)); + MyXMLVisitor::setTagDescription(tag, isFontElement, handleVisitEnter); } void RichText::removeTagDescription(const std::string& tag) diff --git a/cocos/ui/UIRichText.h b/cocos/ui/UIRichText.h index 39270fccbe46..0a3f51f90feb 100644 --- a/cocos/ui/UIRichText.h +++ b/cocos/ui/UIRichText.h @@ -533,7 +533,7 @@ class CC_GUI_DLL RichText : public Widget * @param isFontElement use attributes of text tag * @param handleVisitEnter callback */ - static void setTagDescription(const std::string& tag, bool isFontElement, VisitEnterHandler handleVisitEnter); + static void setTagDescription(const std::string& tag, bool isFontElement, const VisitEnterHandler& handleVisitEnter); /** * @brief remove a callback to own tag.