Skip to content

add new clang-tidy option #19670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Checks: >
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-type-promotion-in-math-fn,
readability-container-size-empty,

WarningsAsErrors: '*'
HeaderFilterRegex: '/(?!external)/.*'
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCAtlasNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ AtlasNode * AtlasNode::create(const std::string& tile, int tileWidth, int tileHe

bool AtlasNode::initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender)
{
CCASSERT(tile.size() > 0, "file size should not be empty");
CCASSERT(!tile.empty(), "file size should not be empty");
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCClippingNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void ClippingNode::setStencil(Node *stencil)

bool ClippingNode::hasContent() const
{
return _children.size() > 0;
return !_children.empty();
}

GLfloat ClippingNode::getAlphaThreshold() const
Expand Down
8 changes: 4 additions & 4 deletions cocos/2d/CCFastTMXTiledMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std:

bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
{
CCASSERT(tmxFile.size()>0, "FastTMXTiledMap: tmx file should not be empty");
CCASSERT(!tmxFile.empty(), "FastTMXTiledMap: tmx file should not be empty");

setContentSize(Size::ZERO);

Expand Down Expand Up @@ -198,7 +198,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
// public
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
{
CCASSERT(layerName.size() > 0, "Invalid layer name!");
CCASSERT(!layerName.empty(), "Invalid layer name!");

for (auto& child : _children)
{
Expand All @@ -218,9 +218,9 @@ TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const

TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
{
CCASSERT(groupName.size() > 0, "Invalid group name!");
CCASSERT(!groupName.empty(), "Invalid group name!");

if (_objectGroups.size()>0)
if (!_objectGroups.empty())
{
for (const auto& objectGroup : _objectGroups)
{
Expand Down
10 changes: 5 additions & 5 deletions cocos/2d/CCMenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ bool MenuItemAtlasFont::initWithString(const std::string& value, const std::stri

bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
{
CCASSERT( value.size() != 0, "value length must be greater than 0");
CCASSERT( !value.empty(), "value length must be greater than 0");
LabelAtlas *label = LabelAtlas::create();
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
if (MenuItemLabel::initWithLabel(label, callback))
Expand Down Expand Up @@ -736,17 +736,17 @@ bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const st
Node *selectedSprite = nullptr;
Node *disabledSprite = nullptr;

if (normalImage.size() >0)
if (!normalImage.empty())
{
normalSprite = Sprite::create(normalImage);
}

if (selectedImage.size() >0)
if (!selectedImage.empty())
{
selectedSprite = Sprite::create(selectedImage);
}

if(disabledImage.size() >0)
if(!disabledImage.empty())
{
disabledSprite = Sprite::create(disabledImage);
}
Expand Down Expand Up @@ -952,7 +952,7 @@ void MenuItemToggle::cleanup()

void MenuItemToggle::setSelectedIndex(unsigned int index)
{
if( index != _selectedIndex && _subItems.size() > 0 )
if( index != _selectedIndex && !_subItems.empty() )
{
_selectedIndex = index;
if (_selectedItem)
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCSpriteBatchNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ ssize_t SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
{
auto& children = sprite->getChildren();

if (children.size() == 0)
if (children.empty())
{
return sprite->getAtlasIndex();
}
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCSpriteFrameCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void SpriteFrameCache::addSpriteFramesWithFileContent(const std::string& plist_c

void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName)
{
CCASSERT(textureFileName.size()>0, "texture name should not be null");
CCASSERT(!textureFileName.empty(), "texture name should not be null");
const std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);
addSpriteFramesWithDictionary(dict, textureFileName, plist);
Expand Down Expand Up @@ -656,7 +656,7 @@ void SpriteFrameCache::reloadSpriteFramesWithDictionary(ValueMap& dictionary, Te

bool SpriteFrameCache::reloadTexture(const std::string& plist)
{
CCASSERT(plist.size()>0, "plist filename should not be nullptr");
CCASSERT(!plist.empty(), "plist filename should not be nullptr");

if (_spriteFramesCache.isPlistUsed(plist)) {
_spriteFramesCache.erasePlistIndex(plist);
Expand Down Expand Up @@ -784,7 +784,7 @@ bool SpriteFrameCache::PlistFramesCache::hasFrame(const std::string &frame) cons
bool SpriteFrameCache::PlistFramesCache::isPlistUsed(const std::string &plist) const
{
auto frames = _indexPlist2Frames.find(plist);
return frames != _indexPlist2Frames.end() && frames->second.size() > 0;
return frames != _indexPlist2Frames.end() && !frames->second.empty();
}

SpriteFrame * SpriteFrameCache::PlistFramesCache::at(const std::string &frame)
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCTMXTiledMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std:

bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
{
CCASSERT(tmxFile.size()>0, "TMXTiledMap: tmx file should not be empty");
CCASSERT(!tmxFile.empty(), "TMXTiledMap: tmx file should not be empty");

_tmxFile = tmxFile;

Expand Down Expand Up @@ -203,7 +203,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
// public
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
{
CCASSERT(layerName.size() > 0, "Invalid layer name!");
CCASSERT(!layerName.empty(), "Invalid layer name!");

for (auto& child : _children)
{
Expand All @@ -223,7 +223,7 @@ TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const

TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const
{
CCASSERT(groupName.size() > 0, "Invalid group name!");
CCASSERT(!groupName.empty(), "Invalid group name!");

for (const auto objectGroup : _objectGroups)
{
Expand Down
8 changes: 4 additions & 4 deletions cocos/2d/CCTMXXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
{
// If this is an external tileset then start parsing that
std::string externalTilesetFilename = attributeDict["source"].asString();
if (externalTilesetFilename != "")
if (!externalTilesetFilename.empty())
{
_externalTilesetFilename = externalTilesetFilename;

Expand Down Expand Up @@ -444,15 +444,15 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
}
else
{
tileset->_sourceImage = _resources + (_resources.size() ? "/" : "") + imagename;
tileset->_sourceImage = _resources + (!_resources.empty() ? "/" : "") + imagename;
}
}
else if (elementName == "data")
{
std::string encoding = attributeDict["encoding"].asString();
std::string compression = attributeDict["compression"].asString();

if (encoding == "")
if (encoding.empty())
{
tmxMapInfo->setLayerAttribs(tmxMapInfo->getLayerAttribs() | TMXLayerAttribNone);

Expand Down Expand Up @@ -482,7 +482,7 @@ void TMXMapInfo::startElement(void* /*ctx*/, const char *name, const char **atts
layerAttribs = tmxMapInfo->getLayerAttribs();
tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
}
CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
CCASSERT( compression.empty() || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
}
else if (encoding == "csv")
{
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCTextFieldTTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeho
if(ret && ret->initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
{
ret->autorelease();
if (placeholder.size()>0)
if (!placeholder.empty())
{
ret->setPlaceHolder(placeholder);
}
Expand All @@ -130,7 +130,7 @@ TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeho
if(ret && ret->initWithPlaceHolder("", fontName, fontSize))
{
ret->autorelease();
if (placeholder.size()>0)
if (!placeholder.empty())
{
ret->setPlaceHolder(placeholder);
}
Expand Down
6 changes: 3 additions & 3 deletions cocos/3d/CCAnimation3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool Animation3D::init(const Animation3DData &data)
_boneCurves[iter.first] = curve;
}

if(iter.second.size() == 0) continue;
if(iter.second.empty()) continue;
std::vector<float> keys;
std::vector<float> values;
for(const auto& keyIter : iter.second)
Expand All @@ -144,7 +144,7 @@ bool Animation3D::init(const Animation3DData &data)
_boneCurves[iter.first] = curve;
}

if(iter.second.size() == 0) continue;
if(iter.second.empty()) continue;
std::vector<float> keys;
std::vector<float> values;
for(const auto& keyIter : iter.second)
Expand All @@ -169,7 +169,7 @@ bool Animation3D::init(const Animation3DData &data)
_boneCurves[iter.first] = curve;
}

if(iter.second.size() == 0) continue;
if(iter.second.empty()) continue;
std::vector<float> keys;
std::vector<float> values;
for(const auto& keyIter : iter.second)
Expand Down
14 changes: 7 additions & 7 deletions cocos/3d/CCBundle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,22 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
attrib.size = 3;
attrib.type = GL_FLOAT;

if (mesh.positions.size())
if (!mesh.positions.empty())
{
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
attrib.attribSizeBytes = attrib.size * sizeof(float);
meshdata->attribs.push_back(attrib);

}
bool hasnormal = false, hastex = false;
if (mesh.normals.size())
if (!mesh.normals.empty())
{
hasnormal = true;
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_NORMAL;
attrib.attribSizeBytes = attrib.size * sizeof(float);
meshdata->attribs.push_back(attrib);
}
if (mesh.texcoords.size())
if (!mesh.texcoords.empty())
{
hastex = true;
attrib.size = 2;
Expand Down Expand Up @@ -1544,7 +1544,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
{
// if id is not a null string, we need to add a suffix of "animation" for seeding.
std::string id_ = id;
if(id != "") id_ = id + "animation";
if(!id.empty()) id_ = id + "animation";

if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS, id_))
return false;
Expand Down Expand Up @@ -1730,7 +1730,7 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue, bo
modelnodedata->subMeshId = part[MESHPARTID].GetString();
modelnodedata->materialId = part[MATERIALID].GetString();

if (modelnodedata->subMeshId == "" || modelnodedata->materialId == "")
if (modelnodedata->subMeshId.empty() || modelnodedata->materialId.empty())
{
CCLOG("warning: Node %s part is missing meshPartId or materialId", nodedata->id.c_str());
CC_SAFE_DELETE(modelnodedata);
Expand Down Expand Up @@ -1874,7 +1874,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton, bool singleSprit
modelnodedata->subMeshId = _binaryReader.readString();
modelnodedata->materialId = _binaryReader.readString();

if (modelnodedata->subMeshId == "" || modelnodedata->materialId == "")
if (modelnodedata->subMeshId.empty() || modelnodedata->materialId.empty())
{
std::string err = "Node " + nodedata->id + " part is missing meshPartId or materialId";
CCLOG("Node %s part is missing meshPartId or materialId", nodedata->id.c_str());
Expand Down Expand Up @@ -2158,7 +2158,7 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id)
if (ref->type == type)
{
// if id is not a null string, we also need to check the Reference's id.
if (id != "" && id != ref->id)
if (!id.empty() && id != ref->id)
{
continue;
}
Expand Down
14 changes: 7 additions & 7 deletions cocos/3d/CCMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ Mesh* Mesh::create(const std::vector<float>& positions, const std::vector<float>
att.type = GL_FLOAT;
att.attribSizeBytes = att.size * sizeof(float);

if (positions.size())
if (!positions.empty())
{
perVertexSizeInFloat += 3;
att.vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
attribs.push_back(att);
}
if (normals.size())
if (!normals.empty())
{
perVertexSizeInFloat += 3;
att.vertexAttrib = GLProgram::VERTEX_ATTRIB_NORMAL;
attribs.push_back(att);
}
if (texs.size())
if (!texs.empty())
{
perVertexSizeInFloat += 2;
att.vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
Expand All @@ -203,8 +203,8 @@ Mesh* Mesh::create(const std::vector<float>& positions, const std::vector<float>
attribs.push_back(att);
}

bool hasNormal = (normals.size() != 0);
bool hasTexCoord = (texs.size() != 0);
bool hasNormal = (!normals.empty());
bool hasTexCoord = (!texs.empty());
//position, normal, texCoordinate into _vertexs
size_t vertexNum = positions.size() / 3;
for(size_t i = 0; i < vertexNum; i++)
Expand Down Expand Up @@ -416,7 +416,7 @@ void Mesh::draw(Renderer* renderer, float globalZOrder, const Mat4& transform, u
if (_skin)
programState->setUniformVec4v("u_matrixPalette", (GLsizei)_skin->getMatrixPaletteSize(), _skin->getMatrixPalette());

if (scene && scene->getLights().size() > 0)
if (scene && !scene->getLights().empty())
setLightUniforms(pass, scene, color, lightMask);
}

Expand Down Expand Up @@ -472,7 +472,7 @@ void Mesh::calculateAABB()
//get skin root
Bone3D* root = nullptr;
Mat4 invBindPose;
if (_skin->_skinBones.size())
if (!_skin->_skinBones.empty())
{
root = _skin->_skinBones.at(0);
while (root) {
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/CCMeshSkin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void MeshSkin::addSkinBone(Bone3D* bone)
Bone3D* MeshSkin::getRootBone() const
{
Bone3D* root = nullptr;
if (_skinBones.size())
if (!_skinBones.empty())
{
root = _skinBones.at(0);
while (root->getParentBone()) {
Expand Down
10 changes: 5 additions & 5 deletions cocos/3d/CCObjLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ namespace tinyobj {
std::string linebuf(&buf[0]);

// Trim newline '\r\n' or '\n'
if (linebuf.size() > 0) {
if (!linebuf.empty()) {
if (linebuf[linebuf.size() - 1] == '\n')
linebuf.erase(linebuf.size() - 1);
}
if (linebuf.size() > 0) {
if (!linebuf.empty()) {
if (linebuf[linebuf.size() - 1] == '\r')
linebuf.erase(linebuf.size() - 1);
}
Expand Down Expand Up @@ -700,11 +700,11 @@ namespace tinyobj {
std::string linebuf(&buf[0]);

// Trim newline '\r\n' or '\n'
if (linebuf.size() > 0) {
if (!linebuf.empty()) {
if (linebuf[linebuf.size() - 1] == '\n')
linebuf.erase(linebuf.size() - 1);
}
if (linebuf.size() > 0) {
if (!linebuf.empty()) {
if (linebuf[linebuf.size() - 1] == '\r')
linebuf.erase(linebuf.size() - 1);
}
Expand Down Expand Up @@ -850,7 +850,7 @@ namespace tinyobj {
token += strspn(token, " \t\r"); // skip tag
}

assert(names.size() > 0);
assert(!names.empty());

// names[0] must be 'g', so skip the 0th element.
if (names.size() > 1) {
Expand Down
Loading