Skip to content

Commit 8addb57

Browse files
JohnCoconutminggo
authored andcommitted
more clang-tidy perf options (#19783)
* performance-move-constructor-init * performance-unnecessary-copy-initialization Disable warnings on RefPtr refcount test case.
1 parent 0cb62f6 commit 8addb57

File tree

18 files changed

+30
-28
lines changed

18 files changed

+30
-28
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Checks: >
77
performance-inefficient-algorithm,
88
performance-inefficient-vector-operation,
99
performance-move-const-arg,
10+
performance-move-constructor-init,
1011
performance-type-promotion-in-math-fn,
12+
performance-unnecessary-copy-initialization,
1113
readability-container-size-empty,
1214
readability-delete-null-pointer,
1315
readability-redundant-control-flow,

cocos/2d/CCFontAtlasCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, cons
119119

120120
FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile)
121121
{
122-
std::string atlasName = plistFile;
122+
const std::string& atlasName = plistFile;
123123

124124
auto it = _atlasMap.find(atlasName);
125125
if ( it == _atlasMap.end() )

cocos/3d/CCSprite3D.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
776776
// Don't override GLProgramState if using manually set Material
777777
if (_usingAutogeneratedGLProgram && scene)
778778
{
779-
const auto lights = scene->getLights();
779+
const auto& lights = scene->getLights();
780780
bool usingLight = false;
781781
for (const auto light : lights) {
782782
usingLight = light->isEnabled() && ((static_cast<unsigned int>(light->getLightFlag()) & _lightMask) > 0);
@@ -851,7 +851,7 @@ const AABB& Sprite3D::getAABB() const
851851
_aabb.reset();
852852
if (!_meshes.empty())
853853
{
854-
Mat4 transform(nodeToWorldTransform);
854+
const Mat4& transform(nodeToWorldTransform);
855855
for (const auto& it : _meshes) {
856856
if (it->isVisible())
857857
_aabb.merge(it->getAABB());

cocos/base/CCProperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Properties* Properties::createNonRefCounted(const std::string& url)
9595
}
9696

9797
// Calculate the file and full namespace path from the specified url.
98-
std::string urlString = url;
98+
const std::string& urlString = url;
9999
std::string fileString;
100100
std::vector<std::string> namespacePath;
101101
calculateNamespacePath(urlString, fileString, namespacePath);

cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void ActionTimelineCache::removeAction(const std::string& fileName)
135135

136136
ActionTimeline* ActionTimelineCache::createAction(const std::string& filename)
137137
{
138-
std::string path = filename;
138+
const std::string& path = filename;
139139
size_t pos = path.find_last_of('.');
140140
std::string suffix = path.substr(pos + 1, path.length());
141141

@@ -440,7 +440,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons
440440
if (action)
441441
return action;
442442

443-
std::string path = fileName;
443+
const std::string& path = fileName;
444444

445445
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
446446

@@ -460,7 +460,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationWithDataBuffer(const cocos2d::
460460
if (action)
461461
return action;
462462

463-
std::string path = fileName;
463+
const std::string& path = fileName;
464464

465465
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
466466

cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void CSLoader::init()
270270

271271
Node* CSLoader::createNode(const std::string& filename)
272272
{
273-
std::string path = filename;
273+
const std::string& path = filename;
274274
size_t pos = path.find_last_of('.');
275275
std::string suffix = path.substr(pos + 1, path.length());
276276

@@ -290,7 +290,7 @@ Node* CSLoader::createNode(const std::string& filename)
290290

291291
Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback &callback)
292292
{
293-
std::string path = filename;
293+
const std::string& path = filename;
294294
size_t pos = path.find_last_of('.');
295295
std::string suffix = path.substr(pos + 1, path.length());
296296

@@ -330,7 +330,7 @@ Node* CSLoader::createNodeWithVisibleSize(const std::string &filename, const ccN
330330

331331
std::string CSLoader::getExtentionName(const std::string& name)
332332
{
333-
std::string path = name;
333+
const std::string& path = name;
334334
size_t pos = path.find_last_of('.');
335335
std::string result = path.substr(pos + 1, path.length());
336336

cocos/physics3d/CCPhysics3D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ btVector3 convertVec3TobtVector3( const cocos2d::Vec3 &vec3 )
5656
cocos2d::Mat4 convertbtTransformToMat4( const btTransform &btTrans )
5757
{
5858
cocos2d::Mat4 mat;
59-
auto rot = btTrans.getBasis();
59+
const auto& rot = btTrans.getBasis();
6060
auto row = rot.getRow(0);
6161
mat.m[0] = row.getX();
6262
mat.m[4] = row.getY();

cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static bool js_cocos2dx_studio_Frame_getEasingParams(JSContext *cx, uint32_t arg
375375
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
376376
if(argc == 0)
377377
{
378-
const std::vector<float> ret = cobj->getEasingParams();
378+
const std::vector<float>& ret = cobj->getEasingParams();
379379

380380
JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, ret.size()));
381381
bool ok = true;

cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class JSB_EditBoxDelegate
149149

150150
jsval dataVal[2];
151151
dataVal[0] = OBJECT_TO_JSVAL(p->obj);
152-
std::string arg1 = text;
152+
const std::string& arg1 = text;
153153
dataVal[1] = std_string_to_jsval(cx, arg1);
154154

155155
JS::RootedValue delegateVal(cx, _JSDelegate);

cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int lua_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(lua_State* L)
115115

116116
if (0 != handler)
117117
{
118-
std::string strMovementID = movementID;
118+
const std::string& strMovementID = movementID;
119119
LuaArmatureMovementEventData movementData(armature,(int)movementType, strMovementID);
120120

121121
LuaArmatureWrapperEventData wrapperData(LuaArmatureWrapperEventData::LuaArmatureWrapperEventType::MOVEMENT_EVENT , (void*)&movementData);
@@ -185,7 +185,7 @@ static int lua_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(lua_State* L)
185185

186186
if (0 != handler)
187187
{
188-
std::string strFrameEventName(frameEventName);
188+
const std::string& strFrameEventName(frameEventName);
189189

190190
LuaArmatureFrameEventData frameData(bone,frameEventName,originFrameIndex,currentFrameIndex);
191191

0 commit comments

Comments
 (0)