Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Checks: >
performance-inefficient-algorithm,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
readability-container-size-empty,
readability-delete-null-pointer,
readability-redundant-control-flow,
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCFontAtlasCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, cons

FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile)
{
std::string atlasName = plistFile;
const std::string& atlasName = plistFile;

auto it = _atlasMap.find(atlasName);
if ( it == _atlasMap.end() )
Expand Down
4 changes: 2 additions & 2 deletions cocos/3d/CCSprite3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
// Don't override GLProgramState if using manually set Material
if (_usingAutogeneratedGLProgram && scene)
{
const auto lights = scene->getLights();
const auto& lights = scene->getLights();
bool usingLight = false;
for (const auto light : lights) {
usingLight = light->isEnabled() && ((static_cast<unsigned int>(light->getLightFlag()) & _lightMask) > 0);
Expand Down Expand Up @@ -851,7 +851,7 @@ const AABB& Sprite3D::getAABB() const
_aabb.reset();
if (!_meshes.empty())
{
Mat4 transform(nodeToWorldTransform);
const Mat4& transform(nodeToWorldTransform);
for (const auto& it : _meshes) {
if (it->isVisible())
_aabb.merge(it->getAABB());
Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CCProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Properties* Properties::createNonRefCounted(const std::string& url)
}

// Calculate the file and full namespace path from the specified url.
std::string urlString = url;
const std::string& urlString = url;
std::string fileString;
std::vector<std::string> namespacePath;
calculateNamespacePath(urlString, fileString, namespacePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void ActionTimelineCache::removeAction(const std::string& fileName)

ActionTimeline* ActionTimelineCache::createAction(const std::string& filename)
{
std::string path = filename;
const std::string& path = filename;
size_t pos = path.find_last_of('.');
std::string suffix = path.substr(pos + 1, path.length());

Expand Down Expand Up @@ -440,7 +440,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons
if (action)
return action;

std::string path = fileName;
const std::string& path = fileName;

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

Expand All @@ -460,7 +460,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationWithDataBuffer(const cocos2d::
if (action)
return action;

std::string path = fileName;
const std::string& path = fileName;

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

Expand Down
6 changes: 3 additions & 3 deletions cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void CSLoader::init()

Node* CSLoader::createNode(const std::string& filename)
{
std::string path = filename;
const std::string& path = filename;
size_t pos = path.find_last_of('.');
std::string suffix = path.substr(pos + 1, path.length());

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

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

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

std::string CSLoader::getExtentionName(const std::string& name)
{
std::string path = name;
const std::string& path = name;
size_t pos = path.find_last_of('.');
std::string result = path.substr(pos + 1, path.length());

Expand Down
2 changes: 1 addition & 1 deletion cocos/physics3d/CCPhysics3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ btVector3 convertVec3TobtVector3( const cocos2d::Vec3 &vec3 )
cocos2d::Mat4 convertbtTransformToMat4( const btTransform &btTrans )
{
cocos2d::Mat4 mat;
auto rot = btTrans.getBasis();
const auto& rot = btTrans.getBasis();
auto row = rot.getRow(0);
mat.m[0] = row.getX();
mat.m[4] = row.getY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static bool js_cocos2dx_studio_Frame_getEasingParams(JSContext *cx, uint32_t arg
JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object");
if(argc == 0)
{
const std::vector<float> ret = cobj->getEasingParams();
const std::vector<float>& ret = cobj->getEasingParams();

JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, ret.size()));
bool ok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class JSB_EditBoxDelegate

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

JS::RootedValue delegateVal(cx, _JSDelegate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static int lua_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(lua_State* L)

if (0 != handler)
{
std::string strMovementID = movementID;
const std::string& strMovementID = movementID;
LuaArmatureMovementEventData movementData(armature,(int)movementType, strMovementID);

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

if (0 != handler)
{
std::string strFrameEventName(frameEventName);
const std::string& strFrameEventName(frameEventName);

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

Expand Down
2 changes: 1 addition & 1 deletion cocos/ui/UILayoutManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Widget* RelativeLayoutManager::getRelativeWidget(Widget* widget)
{
Widget* relativeWidget = nullptr;
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(widget->getLayoutParameter());
const std::string relativeName = layoutParameter->getRelativeToWidgetName();
const std::string& relativeName = layoutParameter->getRelativeToWidgetName();

if (!relativeName.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion extensions/assets-manager/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool Manifest::versionEquals(const Manifest *b) const
bool Manifest::versionGreater(const Manifest *b, const std::function<int(const std::string& versionA, const std::string& versionB)>& handle) const
{
std::string localVersion = getVersion();
std::string bVersion = b->getVersion();
const std::string& bVersion = b->getVersion();
bool greater;
if (handle)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ void Sprite3DWithOBBPerformanceTest::calculateRayByLocationInView(Ray* ray, cons
{
auto dir = Director::getInstance();
auto view = dir->getWinSize();
auto mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
const auto& mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);

Vec3 src = Vec3(location.x, location.y, -1);
Vec3 nearPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void SpritePolygonTestSlider::changeEpsilon(cocos2d::Ref *pSender, cocos2d::ui::
void SpritePolygonTestSlider::updateLabel(const cocos2d::Sprite *sp, const PolygonInfo &pinfo)
{
Label *label = (Label*)(sp->getChildByName(sp->getName()));
auto filename = sp->getName();
const auto& filename = sp->getName();
auto size = pinfo.getRect().size/Director::getInstance()->getContentScaleFactor();
label->setString(filename+"\nVerts: "+Value((int)pinfo.getVertCount()).asString()+ "\nPixels: "+Value((int)(pinfo.getArea()/(size.width*size.height)*100)).asString()+"%");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool UIListViewTest_Vertical::init()
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));

Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();


// create list view ex data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool UIPageViewTest::init()
PageView* pageView = PageView::create();
pageView->setDirection(PageView::Direction::HORIZONTAL);
pageView->setContentSize(size);
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();
pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f);
pageView->removeAllItems();
pageView->setIndicatorEnabled(true);
Expand Down Expand Up @@ -290,7 +290,7 @@ bool UIPageViewTouchPropagationTest::init()
PageView* pageView = PageView::create();
pageView->setContentSize(Size(240.0f, 130.0f));
pageView->setAnchorPoint(Vec2(0.5,0.5));
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();
pageView->setPosition(Vec2(widgetSize.width / 2.0f ,widgetSize.height / 2.0f));
pageView->setBackGroundColor(Color3B::GREEN);
pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
Expand Down Expand Up @@ -487,7 +487,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init()
pageView->setDirection(ui::PageView::Direction::VERTICAL);
pageView->setContentSize(Size(240.0f, 130.0f));
pageView->setAnchorPoint(Vec2(0.5,0.5));
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();
pageView->setPosition(Vec2(widgetSize.width / 2.0f ,widgetSize.height / 2.0f));
pageView->setBackGroundColor(Color3B::GREEN);
pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
Expand Down Expand Up @@ -784,7 +784,7 @@ bool UIPageViewVerticalTest::init()
pageView->setIndicatorEnabled(true);
pageView->setDirection(ui::PageView::Direction::VERTICAL);
pageView->setContentSize(Size(240.0f, 130.0f));
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();
pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f);
pageView->removeAllItems();

Expand Down Expand Up @@ -948,7 +948,7 @@ bool UIPageViewChildSizeTest::init()
PageView* pageView = PageView::create();
pageView->setDirection(PageView::Direction::HORIZONTAL);
pageView->setContentSize(size);
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();
pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f);
pageView->removeAllItems();
pageView->setIndicatorEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool UIScrollViewTest_Horizontal::init()
scrollView->setInnerContainerSize(scrollView->getContentSize());
scrollView->setScrollBarPositionFromCorner(Vec2(4, 4));
scrollView->setScrollBarColor(Color3B::YELLOW);
Size backgroundSize = background->getContentSize();
const Size& backgroundSize = background->getContentSize();
scrollView->setPosition((widgetSize - scrollView->getContentSize()) / 2.0f);
_uiLayer->addChild(scrollView);

Expand Down
4 changes: 2 additions & 2 deletions tests/cpp-tests/Classes/UnitTest/RefPtrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ void RefPtrTest::onEnter()
CC_ASSERT((__String*) nullptr == ref3.get());

// Copy constructor
RefPtr<__String> ref4(ref2);
RefPtr<__String> ref4(ref2); // NOLINT(performance-unnecessary-copy-initialization)
CC_ASSERT(strcmp("Hello", ref4->getCString()) == 0);
CC_ASSERT(3 == ref2->getReferenceCount());
CC_ASSERT(3 == ref4->getReferenceCount());

// Copy constructor with nullptr reference
RefPtr<Ref> ref5(ref1);
RefPtr<Ref> ref5(ref1); // NOLINT(performance-unnecessary-copy-initialization)
CC_ASSERT((Ref*) nullptr == ref5.get());
}

Expand Down