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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Checks: >
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
modernize-redundant-void-arg,
modernize-use-emplace,

WarningsAsErrors: '*'
HeaderFilterRegex: '/(?!external)/.*'
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCAutoPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ std::vector<cocos2d::Vec2> AutoPolygon::marchSquare(const Rect& rect, const Vec2
}
else
{
_points.push_back(Vec2((float)(curx - rect.origin.x) / _scaleFactor, (float)(rect.size.height - cury + rect.origin.y) / _scaleFactor));
_points.emplace_back((float)(curx - rect.origin.x) / _scaleFactor, (float)(rect.size.height - cury + rect.origin.y) / _scaleFactor);
}

count++;
Expand Down Expand Up @@ -569,7 +569,7 @@ std::vector<Vec2> AutoPolygon::expand(const std::vector<Vec2>& points, const coc
}
for(const auto& pt : p2->Contour)
{
outPoints.push_back(Vec2(pt.X/PRECISION, pt.Y/PRECISION));
outPoints.emplace_back(pt.X/PRECISION, pt.Y/PRECISION);
}
return outPoints;
}
Expand Down
18 changes: 9 additions & 9 deletions cocos/3d/CCBundle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
meshdata->subMeshIndices.push_back(submesh.second);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), submesh.second));
sprintf(str, "%d", ++i);
meshdata->subMeshIds.push_back(str);
meshdata->subMeshIds.emplace_back(str);

auto modelnode = new (std::nothrow) ModelData();
modelnode->materialId = submesh.first == -1 ? "" : materials[submesh.first].name;
Expand Down Expand Up @@ -474,7 +474,7 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
CCLOG("warning: Failed to read meshdata: aabb '%s'.", _path.c_str());
goto FAILED;
}
meshData->subMeshAABB.push_back(AABB(Vec3(aabb[0], aabb[1], aabb[2]), Vec3(aabb[3], aabb[4], aabb[5])));
meshData->subMeshAABB.emplace_back(Vec3(aabb[0], aabb[1], aabb[2]), Vec3(aabb[3], aabb[4], aabb[5]));
}
else
{
Expand Down Expand Up @@ -774,7 +774,7 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
{
std::vector<unsigned short> indexArray;
const rapidjson::Value& mesh_part = mesh_part_array[i];
meshData->subMeshIds.push_back(mesh_part[ID].GetString());
meshData->subMeshIds.emplace_back(mesh_part[ID].GetString());
// index_number
const rapidjson::Value& indices_val_array = mesh_part[INDICES];
for (rapidjson::SizeType j = 0, indices_val_array_size = indices_val_array.Size(); j < indices_val_array_size; ++j)
Expand All @@ -792,7 +792,7 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
mesh_part_aabb[(rapidjson::SizeType)1].GetDouble(), mesh_part_aabb[(rapidjson::SizeType)2].GetDouble());
Vec3 max(mesh_part_aabb[(rapidjson::SizeType)3].GetDouble(),
mesh_part_aabb[(rapidjson::SizeType)4].GetDouble(), mesh_part_aabb[(rapidjson::SizeType)5].GetDouble());
meshData->subMeshAABB.push_back(AABB(min, max));
meshData->subMeshAABB.emplace_back(min, max);
}
else
{
Expand Down Expand Up @@ -1321,7 +1321,7 @@ bool Bundle3D::loadSkinDataBinary(SkinData* skindata)
CCLOG("warning: Failed to load SkinData: bindpos '%s'.", _path.c_str());
return false;
}
skindata->inverseBindPoseMatrices.push_back(bindpos);
skindata->inverseBindPoseMatrices.emplace_back(bindpos);
}

skindata->skinBoneOriginMatrices.resize(boneNum);
Expand All @@ -1335,7 +1335,7 @@ bool Bundle3D::loadSkinDataBinary(SkinData* skindata)
{
skindata->addNodeBoneNames(boneName);
rootIndex = skindata->getBoneNameIndex(boneName);
skindata->nodeBoneOriginMatrices.push_back(bindShape);
skindata->nodeBoneOriginMatrices.emplace_back(bindShape);
}
else
{
Expand Down Expand Up @@ -1367,7 +1367,7 @@ bool Bundle3D::loadSkinDataBinary(SkinData* skindata)
{
skindata->addNodeBoneNames(id);
index = skindata->getBoneNameIndex(id);
skindata->nodeBoneOriginMatrices.push_back(transform);
skindata->nodeBoneOriginMatrices.emplace_back(transform);
}
else
{
Expand Down Expand Up @@ -1755,7 +1755,7 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue, bo
return nullptr;
}

modelnodedata->bones.push_back(bone[NODE].GetString());
modelnodedata->bones.emplace_back(bone[NODE].GetString());

Mat4 invbindpos;
const rapidjson::Value& jinvbindpos = bone[TRANSFORM];
Expand Down Expand Up @@ -2212,7 +2212,7 @@ std::vector<Vec3> Bundle3D::getTrianglesList(const std::string& path)
int preVertexSize = iter->getPerVertexSize() / sizeof(float);
for (const auto& indexArray : iter->subMeshIndices){
for (auto i : indexArray){
trianglesList.push_back(Vec3(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1], iter->vertex[i * preVertexSize + 2]));
trianglesList.emplace_back(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1], iter->vertex[i * preVertexSize + 2]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/3d/CCMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Mesh* Mesh::create(const std::vector<float>& vertices, int /*perVertexSizeInFloa
meshdata.attribs = attribs;
meshdata.vertex = vertices;
meshdata.subMeshIndices.push_back(indices);
meshdata.subMeshIds.push_back("");
meshdata.subMeshIds.emplace_back("");
auto meshvertexdata = MeshVertexData::create(meshdata);
auto indexData = meshvertexdata->getMeshIndexDataByIndex(0);

Expand Down
2 changes: 1 addition & 1 deletion cocos/base/CCConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ void Console::log(const char* buf)
{
if( _sendDebugStrings ) {
_DebugStringsMutex.lock();
_DebugStrings.push_back(buf);
_DebugStrings.emplace_back(buf);
_DebugStringsMutex.unlock();
}
}
Expand Down
8 changes: 4 additions & 4 deletions cocos/base/CCProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void Properties::readProperties()
else
{
// Normal name/value pair
_properties.push_back(Property(name, value));
_properties.emplace_back(name, value);
}
}
else
Expand Down Expand Up @@ -383,11 +383,11 @@ void Properties::readProperties()
// Store "name value" as a name/value pair, or even just "name".
if (value != NULL)
{
_properties.push_back(Property(name, value));
_properties.emplace_back(name, value);
}
else
{
_properties.push_back(Property(name, ""));
_properties.emplace_back(name, "");
}
}
}
Expand Down Expand Up @@ -832,7 +832,7 @@ bool Properties::setString(const char* name, const char* value)
}

// There is no property with this name, so add one
_properties.push_back(Property(name, value ? value : ""));
_properties.emplace_back(name, value ? value : "");
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion cocos/editor-support/cocostudio/CCColliderDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ void ColliderDetector::addContourData(ContourData *contourData)
std::vector<Vec2> &calculatedVertexList = colliderBody->_calculatedVertexList;

unsigned long num = contourData->vertexList.size();
calculatedVertexList.reserve(num);
for (unsigned long i = 0; i < num; i++)
{
calculatedVertexList.push_back(Vec2());
calculatedVertexList.emplace_back();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be just use reserve here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. reserve can be used here. However, upon reading the context around this line, I found it hard to understand.

calculatedVertexList is a reference to a member,

std::vector<Vec2> &calculatedVertexList = colliderBody->_calculatedVertexList;

It's initialized in

#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
    _calculatedVertexList = Array::create();
    CC_SAFE_RETAIN(_calculatedVertexList);
#endif

Does the code in the macro ever run? I am not familiar with the ColliderBody class. The following line wouldn't compile.

std::vector<cocos2d::Vec2> vertex_list = Array::create();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with it too. But the codes is calculatedVertexList.emplace_back(); is not easy to understand. It seems it emplace back nothing.

Copy link
Contributor Author

@JohnCoconut JohnCoconut Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emplace_back() means default constructor being used. For example,

std::vector<std::string> v;
v.emplace_back();

appends a empty string to v.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, i understand.

}
#endif
}
Expand Down
10 changes: 5 additions & 5 deletions cocos/navmesh/CCNavMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void cocos2d::NavMesh::findPath(const Vec3 &start, const Vec3 &end, std::vector<
//dtVcopy(&m_smoothPath[m_nsmoothPath * 3], iterPos);
//m_nsmoothPath++;

pathPoints.push_back(Vec3(iterPos[0], iterPos[1], iterPos[2]));
pathPoints.emplace_back(iterPos[0], iterPos[1], iterPos[2]);
nsmoothPath++;

// Move towards target a small advancement at a time until target reached or
Expand Down Expand Up @@ -571,7 +571,7 @@ void cocos2d::NavMesh::findPath(const Vec3 &start, const Vec3 &end, std::vector<
{
//dtVcopy(&m_smoothPath[m_nsmoothPath * 3], iterPos);
//m_nsmoothPath++;
pathPoints.push_back(Vec3(iterPos[0], iterPos[1], iterPos[2]));
pathPoints.emplace_back(iterPos[0], iterPos[1], iterPos[2]);
nsmoothPath++;
}
break;
Expand Down Expand Up @@ -602,14 +602,14 @@ void cocos2d::NavMesh::findPath(const Vec3 &start, const Vec3 &end, std::vector<
{
//dtVcopy(&m_smoothPath[m_nsmoothPath * 3], startPos);
//m_nsmoothPath++;
pathPoints.push_back(Vec3(startPos[0], startPos[1], startPos[2]));
pathPoints.emplace_back(startPos[0], startPos[1], startPos[2]);
nsmoothPath++;
// Hack to make the dotted path not visible during off-mesh connection.
if (nsmoothPath & 1)
{
//dtVcopy(&m_smoothPath[m_nsmoothPath * 3], startPos);
//m_nsmoothPath++;
pathPoints.push_back(Vec3(startPos[0], startPos[1], startPos[2]));
pathPoints.emplace_back(startPos[0], startPos[1], startPos[2]);
nsmoothPath++;
}
}
Expand All @@ -627,7 +627,7 @@ void cocos2d::NavMesh::findPath(const Vec3 &start, const Vec3 &end, std::vector<
//dtVcopy(&m_smoothPath[m_nsmoothPath * 3], iterPos);
//m_nsmoothPath++;

pathPoints.push_back(Vec3(iterPos[0], iterPos[1], iterPos[2]));
pathPoints.emplace_back(iterPos[0], iterPos[1], iterPos[2]);
nsmoothPath++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/network/CCDownloader-curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ namespace cocos2d { namespace network {
if (DownloadTask::ERROR_NO_ERROR == coTask->_errCode)
{
lock_guard<mutex> lock(_requestMutex);
_requestQueue.push_back(make_pair(task, coTask));
_requestQueue.emplace_back(task, coTask);
}
else
{
lock_guard<mutex> lock(_finishedMutex);
_finishedQueue.push_back(make_pair(task, coTask));
_finishedQueue.emplace_back(task, coTask);
}
}

Expand Down
46 changes: 23 additions & 23 deletions cocos/network/SocketIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ class SocketIOPacketV10x : public SocketIOPacket

SocketIOPacket::SocketIOPacket() :_endpointseparator(""), _separator(":")
{
_types.push_back("disconnect");
_types.push_back("connect");
_types.push_back("heartbeat");
_types.push_back("message");
_types.push_back("json");
_types.push_back("event");
_types.push_back("ack");
_types.push_back("error");
_types.push_back("noop");
_types.emplace_back("disconnect");
_types.emplace_back("connect");
_types.emplace_back("heartbeat");
_types.emplace_back("message");
_types.emplace_back("json");
_types.emplace_back("event");
_types.emplace_back("ack");
_types.emplace_back("error");
_types.emplace_back("noop");
}

SocketIOPacket::~SocketIOPacket()
Expand Down Expand Up @@ -236,20 +236,20 @@ SocketIOPacketV10x::SocketIOPacketV10x()
{
_separator = "";
_endpointseparator = ",";
_types.push_back("disconnected");
_types.push_back("connected");
_types.push_back("heartbeat");
_types.push_back("pong");
_types.push_back("message");
_types.push_back("upgrade");
_types.push_back("noop");
_typesMessage.push_back("connect");
_typesMessage.push_back("disconnect");
_typesMessage.push_back("event");
_typesMessage.push_back("ack");
_typesMessage.push_back("error");
_typesMessage.push_back("binarevent");
_typesMessage.push_back("binaryack");
_types.emplace_back("disconnected");
_types.emplace_back("connected");
_types.emplace_back("heartbeat");
_types.emplace_back("pong");
_types.emplace_back("message");
_types.emplace_back("upgrade");
_types.emplace_back("noop");
_typesMessage.emplace_back("connect");
_typesMessage.emplace_back("disconnect");
_typesMessage.emplace_back("event");
_typesMessage.emplace_back("ack");
_typesMessage.emplace_back("error");
_typesMessage.emplace_back("binarevent");
_typesMessage.emplace_back("binaryack");
}

int SocketIOPacketV10x::typeAsNumber()const
Expand Down
4 changes: 2 additions & 2 deletions cocos/platform/CCFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ bool FileUtils::init()
{
DECLARE_GUARD;
_searchPathArray.push_back(_defaultResRootPath);
_searchResolutionsOrderArray.push_back("");
_searchResolutionsOrderArray.emplace_back("");
return true;
}

Expand Down Expand Up @@ -955,7 +955,7 @@ void FileUtils::setSearchResolutionsOrder(const std::vector<std::string>& search

if (!existDefault)
{
_searchResolutionsOrderArray.push_back("");
_searchResolutionsOrderArray.emplace_back("");
}
}

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 @@ -532,7 +532,7 @@ void Manifest::loadManifest(const rapidjson::Document &json)
for (rapidjson::SizeType i = 0; i < paths.Size(); ++i)
{
if (paths[i].IsString()) {
_searchPaths.push_back(paths[i].GetString());
_searchPaths.emplace_back(paths[i].GetString());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/cpp-empty-test/Classes/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ bool AppDelegate::applicationDidFinishLaunching()
// If the frame's height is larger than the height of medium resource size, select large resource.
if (frameSize.height > mediumResource.size.height)
{
searchPath.push_back(largeResource.directory);
searchPath.emplace_back(largeResource.directory);

director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
}
// If the frame's height is larger than the height of small resource size, select medium resource.
else if (frameSize.height > smallResource.size.height)
{
searchPath.push_back(mediumResource.directory);
searchPath.emplace_back(mediumResource.directory);

director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
}
// If the frame's height is smaller than the height of medium resource size, select small resource.
else
{
searchPath.push_back(smallResource.directory);
searchPath.emplace_back(smallResource.directory);

director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
}
Expand Down
14 changes: 7 additions & 7 deletions tests/cpp-tests/Classes/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ bool AppDelegate::applicationDidFinishLaunching()
if (screenSize.height > 320)
{
auto resourceSize = Size(960, 640);
searchPaths.push_back("hd");
searchPaths.push_back("ccs-res/hd");
searchPaths.push_back("ccs-res");
searchPaths.push_back("Manifests");
searchPaths.emplace_back("hd");
searchPaths.emplace_back("ccs-res/hd");
searchPaths.emplace_back("ccs-res");
searchPaths.emplace_back("Manifests");
director->setContentScaleFactor(resourceSize.height/designSize.height);

searchPaths.push_back("hd/ActionTimeline");
searchPaths.emplace_back("hd/ActionTimeline");
}
else
{
searchPaths.push_back("ccs-res");
searchPaths.emplace_back("ccs-res");

searchPaths.push_back("ActionTimeline");
searchPaths.emplace_back("ActionTimeline");
}

fileUtils->setSearchPaths(searchPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void HttpClientTest::onMenuPostTestClicked(cocos2d::Ref *sender, bool isImmediat
request->setUrl("http://httpbin.org/post");
request->setRequestType(HttpRequest::Type::POST);
std::vector<std::string> headers;
headers.push_back("Content-Type: application/json; charset=utf-8");
headers.emplace_back("Content-Type: application/json; charset=utf-8");
request->setHeaders(headers);
request->setResponseCallback(CC_CALLBACK_2(HttpClientTest::onHttpRequestCompleted, this));

Expand Down Expand Up @@ -295,7 +295,7 @@ void HttpClientTest::onMenuPutTestClicked(Ref *sender, bool isImmediate)
request->setUrl("http://httpbin.org/put");
request->setRequestType(HttpRequest::Type::PUT);
std::vector<std::string> headers;
headers.push_back("Content-Type: application/json; charset=utf-8");
headers.emplace_back("Content-Type: application/json; charset=utf-8");
request->setHeaders(headers);
request->setResponseCallback(CC_CALLBACK_2(HttpClientTest::onHttpRequestCompleted, this));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void WebSocketDelayTest::startTestCallback(Ref* sender)
_wsiSendText = new network::WebSocket();

std::vector<std::string> protocols;
protocols.push_back("myprotocol_1");
protocols.push_back("myprotocol_2");
protocols.emplace_back("myprotocol_1");
protocols.emplace_back("myprotocol_2");
if (!_wsiSendText->init(*this, "wss://echo.websocket.org", &protocols, "cacert.pem"))
{
CC_SAFE_DELETE(_wsiSendText);
Expand Down
Loading