Skip to content

enable more clang-tidy performance options #19656

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 4 commits into from
May 6, 2019
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
5 changes: 5 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Checks: >
-*,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-type-promotion-in-math-fn,

WarningsAsErrors: '*'
HeaderFilterRegex: '/(?!external)/.*'
Expand Down
25 changes: 13 additions & 12 deletions cocos/2d/CCFastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ THE SOFTWARE.

*/
#include "2d/CCFastTMXLayer.h"
#include <cmath>
#include "2d/CCFastTMXTiledMap.h"
#include "2d/CCSprite.h"
#include "2d/CCCamera.h"
Expand Down Expand Up @@ -209,10 +210,10 @@ void TMXLayer::updateTiles(const Rect& culledRect)
visibleTiles.origin.y += 1;

// if x=0.7, width=9.5, we need to draw number 0~10 of tiles, and so is height.
visibleTiles.size.width = ceil(visibleTiles.origin.x + visibleTiles.size.width) - floor(visibleTiles.origin.x);
visibleTiles.size.height = ceil(visibleTiles.origin.y + visibleTiles.size.height) - floor(visibleTiles.origin.y);
visibleTiles.origin.x = floor(visibleTiles.origin.x);
visibleTiles.origin.y = floor(visibleTiles.origin.y);
visibleTiles.size.width = std::ceil(visibleTiles.origin.x + visibleTiles.size.width) - std::floor(visibleTiles.origin.x);
visibleTiles.size.height = std::ceil(visibleTiles.origin.y + visibleTiles.size.height) - std::floor(visibleTiles.origin.y);
visibleTiles.origin.x = std::floor(visibleTiles.origin.x);
visibleTiles.origin.y = std::floor(visibleTiles.origin.y);

// for the bigger tiles.
int tilesOverX = 0;
Expand All @@ -221,8 +222,8 @@ void TMXLayer::updateTiles(const Rect& culledRect)
float tileSizeMax = std::max(tileSize.width, tileSize.height);
if (_layerOrientation == FAST_TMX_ORIENTATION_ORTHO)
{
tilesOverX = ceil(tileSizeMax / mapTileSize.width) - 1;
tilesOverY = ceil(tileSizeMax / mapTileSize.height) - 1;
tilesOverX = std::ceil(tileSizeMax / mapTileSize.width) - 1;
tilesOverY = std::ceil(tileSizeMax / mapTileSize.height) - 1;

if (tilesOverX < 0) tilesOverX = 0;
if (tilesOverY < 0) tilesOverY = 0;
Expand All @@ -234,8 +235,8 @@ void TMXLayer::updateTiles(const Rect& culledRect)
if (overTileRect.size.height < 0) overTileRect.size.height = 0;
overTileRect = RectApplyTransform(overTileRect, nodeToTileTransform);

tilesOverX = ceil(overTileRect.origin.x + overTileRect.size.width) - floor(overTileRect.origin.x);
tilesOverY = ceil(overTileRect.origin.y + overTileRect.size.height) - floor(overTileRect.origin.y);
tilesOverX = std::ceil(overTileRect.origin.x + overTileRect.size.width) - std::floor(overTileRect.origin.x);
tilesOverY = std::ceil(overTileRect.origin.y + overTileRect.size.height) - std::floor(overTileRect.origin.y);
}
else
{
Expand Down Expand Up @@ -346,15 +347,15 @@ void TMXLayer::setupTiles()
switch (_layerOrientation)
{
case FAST_TMX_ORIENTATION_ORTHO:
_screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 1;
_screenGridSize.height = ceil(screenSize.height / _mapTileSize.height) + 1;
_screenGridSize.width = std::ceil(screenSize.width / _mapTileSize.width) + 1;
_screenGridSize.height = std::ceil(screenSize.height / _mapTileSize.height) + 1;

// tiles could be bigger than the grid, add additional rows if needed
_screenGridSize.height += _tileSet->_tileSize.height / _mapTileSize.height;
break;
case FAST_TMX_ORIENTATION_ISO:
_screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 2;
_screenGridSize.height = ceil(screenSize.height / (_mapTileSize.height/2)) + 4;
_screenGridSize.width = std::ceil(screenSize.width / _mapTileSize.width) + 2;
_screenGridSize.height = std::ceil(screenSize.height / (_mapTileSize.height/2)) + 4;
break;
case FAST_TMX_ORIENTATION_HEX:
default:
Expand Down
5 changes: 3 additions & 2 deletions cocos/2d/CCLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/

#include "2d/CCLight.h"
#include <cmath>
#include "2d/CCScene.h"

NS_CC_BEGIN
Expand Down Expand Up @@ -60,7 +61,7 @@ void BaseLight::onExit()

void BaseLight::setRotationFromDirection( const Vec3 &direction )
{
float projLen = sqrt(direction.x * direction.x + direction.z * direction.z);
float projLen = std::sqrt(direction.x * direction.x + direction.z * direction.z);
float rotY = CC_RADIANS_TO_DEGREES(atan2f(-direction.x, -direction.z));
float rotX = -CC_RADIANS_TO_DEGREES(atan2f(-direction.y, projLen));
setRotation3D(Vec3(rotX, rotY, 0.0f));
Expand Down Expand Up @@ -205,4 +206,4 @@ AmbientLight::~AmbientLight()

}

NS_CC_END
NS_CC_END
9 changes: 5 additions & 4 deletions cocos/2d/CCTweenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
****************************************************************************/

#include "2d/CCTweenFunction.h"
#include <cmath>

#define _USE_MATH_DEFINES // needed for M_PI and M_PI2
#include <math.h> // M_PI
Expand Down Expand Up @@ -316,20 +317,20 @@ float expoEaseInOut(float time)
// Circ Ease
float circEaseIn(float time)
{
return -1 * (sqrt(1 - time * time) - 1);
return -1 * (std::sqrt(1 - time * time) - 1);
}
float circEaseOut(float time)
{
time = time - 1;
return sqrt(1 - time * time);
return std::sqrt(1 - time * time);
}
float circEaseInOut(float time)
{
time = time * 2;
if (time < 1)
return -0.5f * (sqrt(1 - time * time) - 1);
return -0.5f * (std::sqrt(1 - time * time) - 1);
time -= 2;
return 0.5f * (sqrt(1 - time * time) + 1);
return 0.5f * (std::sqrt(1 - time * time) + 1);
}


Expand Down
9 changes: 5 additions & 4 deletions cocos/3d/CCOBB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
****************************************************************************/

#include "3d/CCOBB.h"
#include <cmath>

NS_CC_BEGIN

Expand Down Expand Up @@ -109,7 +110,7 @@ static void _getEigenVectors(Mat4* vout, Vec3* dout, Mat4 a)
for(i = 0; i < 50; i++)
{
sm = 0.0;
for(ip = 0; ip < n; ip++) for(iq = ip+1; iq < n; iq++) sm += fabs(a.m[ip + 4 * iq]);
for(ip = 0; ip < n; ip++) for(iq = ip+1; iq < n; iq++) sm += std::fabs(a.m[ip + 4 * iq]);
if( fabs(sm) < FLT_EPSILON )
{
v.transpose();
Expand All @@ -127,15 +128,15 @@ static void _getEigenVectors(Mat4* vout, Vec3* dout, Mat4 a)
{
for(iq = ip + 1; iq < n; iq++)
{
g = 100.0 * fabs(a.m[ip + iq * 4]);
g = 100.0 * std::fabs(a.m[ip + iq * 4]);
float dmip = _getElement(d, ip);
float dmiq = _getElement(d, iq);

if( i>3 && fabs(dmip) + g == fabs(dmip) && fabs(dmiq) + g == fabs(dmiq) )
if( i>3 && std::fabs(dmip) + g == std::fabs(dmip) && std::fabs(dmiq) + g == std::fabs(dmiq) )
{
a.m[ip + 4 * iq] = 0.0;
}
else if (fabs(a.m[ip + 4 * iq]) > tresh)
else if (std::fabs(a.m[ip + 4 * iq]) > tresh)
{
h = dmiq - dmip;
if (fabs(h) + g == fabs(h))
Expand Down
1 change: 1 addition & 0 deletions cocos/base/ccUTF8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ long cc_utf8_strlen (const char * p, int /*max*/)
unsigned int cc_utf8_find_last_not_char(const std::vector<unsigned short>& str, unsigned short c)
{
std::vector<char16_t> char16Vector;
char16Vector.reserve(str.size());
for (const auto& e : str)
{
char16Vector.push_back(e);
Expand Down
2 changes: 1 addition & 1 deletion cocos/deprecated/CCString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ __String* __String::createWithFormat(const char* format, ...)
__String* __String::createWithContentsOfFile(const std::string &filename)
{
std::string str = FileUtils::getInstance()->getStringFromFile(filename);
return __String::create(std::move(str));
return __String::create(str);
}

void __String::acceptVisitor(DataVisitor &visitor)
Expand Down
33 changes: 17 additions & 16 deletions cocos/editor-support/cocostudio/CCTransformHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
****************************************************************************/

#include "editor-support/cocostudio/CCTransformHelp.h"
#include <cmath>
#include "editor-support/cocostudio/CCUtilMath.h"

using namespace cocos2d;
Expand Down Expand Up @@ -99,8 +100,8 @@ void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix)
{
if (node.skewX == -node.skewY)
{
double sine = sin(node.skewX);
double cosine = cos(node.skewX);
double sine = std::sin(node.skewX);
double cosine = std::cos(node.skewX);

matrix.a = node.scaleX * cosine;
matrix.b = node.scaleX * -sine;
Expand All @@ -109,10 +110,10 @@ void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix)
}
else
{
matrix.a = node.scaleX * cos(node.skewY);
matrix.b = node.scaleX * sin(node.skewY);
matrix.c = node.scaleY * sin(node.skewX);
matrix.d = node.scaleY * cos(node.skewX);
matrix.a = node.scaleX * std::cos(node.skewY);
matrix.b = node.scaleX * std::sin(node.skewY);
matrix.c = node.scaleY * std::sin(node.skewX);
matrix.d = node.scaleY * std::cos(node.skewX);
}

matrix.tx = node.x;
Expand All @@ -125,8 +126,8 @@ void TransformHelp::nodeToMatrix(const BaseData &node, Mat4 &matrix)

if (node.skewX == -node.skewY)
{
double sine = sin(node.skewX);
double cosine = cos(node.skewX);
double sine = std::sin(node.skewX);
double cosine = std::cos(node.skewX);

matrix.m[0] = node.scaleX * cosine;
matrix.m[1] = node.scaleX * -sine;
Expand All @@ -135,10 +136,10 @@ void TransformHelp::nodeToMatrix(const BaseData &node, Mat4 &matrix)
}
else
{
matrix.m[0] = node.scaleX * cos(node.skewY);
matrix.m[1] = node.scaleX * sin(node.skewY);
matrix.m[4] = node.scaleY * sin(node.skewX);
matrix.m[5] = node.scaleY * cos(node.skewX);
matrix.m[0] = node.scaleX * std::cos(node.skewY);
matrix.m[1] = node.scaleX * std::sin(node.skewY);
matrix.m[4] = node.scaleY * std::sin(node.skewX);
matrix.m[5] = node.scaleY * std::cos(node.skewX);
}

matrix.m[12] = node.x;
Expand Down Expand Up @@ -166,8 +167,8 @@ void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node)

node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f);
node.skewY = atan2f(helpPoint2.y, helpPoint2.x);
node.scaleX = sqrt(matrix.a * matrix.a + matrix.b * matrix.b);
node.scaleY = sqrt(matrix.c * matrix.c + matrix.d * matrix.d);
node.scaleX = std::sqrt(matrix.a * matrix.a + matrix.b * matrix.b);
node.scaleY = std::sqrt(matrix.c * matrix.c + matrix.d * matrix.d);
node.x = matrix.tx;
node.y = matrix.ty;
}
Expand All @@ -192,8 +193,8 @@ void TransformHelp::matrixToNode(const Mat4 &matrix, BaseData &node)

node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f);
node.skewY = atan2f(helpPoint2.y, helpPoint2.x);
node.scaleX = sqrt(matrix.m[0] * matrix.m[0] + matrix.m[1] * matrix.m[1]);
node.scaleY = sqrt(matrix.m[4] * matrix.m[4] + matrix.m[5] * matrix.m[5]);
node.scaleX = std::sqrt(matrix.m[0] * matrix.m[0] + matrix.m[1] * matrix.m[1]);
node.scaleY = std::sqrt(matrix.m[4] * matrix.m[4] + matrix.m[5] * matrix.m[5]);
node.x = matrix.m[12];
node.y = matrix.m[13];
}
Expand Down
5 changes: 3 additions & 2 deletions cocos/editor-support/cocostudio/CCUtilMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
****************************************************************************/

#include "editor-support/cocostudio/CCUtilMath.h"
#include <cmath>

using namespace cocos2d;

Expand Down Expand Up @@ -72,8 +73,8 @@ Vec2 circleTo(float t, Vec2 &center, float radius, float fromRadian, float radia
{
Vec2 p;

p.x = center.x + radius * cos(fromRadian + radianDif * t);
p.y = center.y + radius * sin(fromRadian + radianDif * t);
p.x = center.x + radius * std::cos(fromRadian + radianDif * t);
p.y = center.y + radius * std::sin(fromRadian + radianDif * t);

return p;
}
Expand Down
5 changes: 3 additions & 2 deletions cocos/editor-support/cocostudio/TriggerMng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
****************************************************************************/

#include "editor-support/cocostudio/TriggerMng.h"
#include <cmath>
#include "json/prettywriter.h"
#include "json/stringbuffer.h"
#include "base/CCDirector.h"
Expand Down Expand Up @@ -275,7 +276,7 @@ void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader
{
int nV = atoi(str3);
float fV = utils::atof(str3);
if (fabs(nV - fV) < 0.0000001)
if (std::fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
Expand Down Expand Up @@ -351,7 +352,7 @@ void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader
{
int nV = atoi(str5);
float fV = utils::atof(str5);
if (fabs(nV - fV) < 0.0000001)
if (std::fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/editor-support/spine/Bone.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota
za *= s;
zc *= s;
s = SQRT(za * za + zc * zc);
r = PI / 2 + atan2(zc, za);
r = PI / 2 + atan2f(zc, za);
zb = COS(r) * s;
zd = SIN(r) * s;
la = COS_DEG(shearX) * scaleX;
Expand Down
4 changes: 2 additions & 2 deletions cocos/platform/CCFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ std::string FileUtils::fullPathForDirectory(const std::string &dir) const
{
for (const auto& resolutionIt : _searchResolutionsOrderArray)
{
fullpath = searchIt + longdir + resolutionIt;
fullpath.append(searchIt).append(longdir).append(resolutionIt);
auto exists = isDirectoryExistInternal(fullpath);

if (exists && !fullpath.empty())
Expand Down Expand Up @@ -1180,7 +1180,7 @@ bool FileUtils::isDirectoryExist(const std::string& dirPath) const
for (const auto& resolutionIt : _searchResolutionsOrderArray)
{
// searchPath + file_path + resourceDirectory
fullpath = fullPathForDirectory(searchIt + dirPath + resolutionIt);
fullpath = fullPathForDirectory(std::string(searchIt).append(dirPath).append(resolutionIt));
if (isDirectoryExistInternal(fullpath))
{
_fullPathCacheDir.emplace(dirPath, fullpath);
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/CCGLProgramState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ bool GLProgramState::init(GLProgram* glprogram)

for(auto &uniform : _glprogram->_userUniforms) {
UniformValue value(&uniform.second, _glprogram);
_uniforms[uniform.second.location] = std::move(value);
_uniforms[uniform.second.location] = value;
_uniformsByName[uniform.first] = uniform.second.location;
}

Expand Down
7 changes: 4 additions & 3 deletions extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include "CCControlPotentiometer.h"
#include <cmath>

NS_CC_EXT_BEGIN

Expand Down Expand Up @@ -206,7 +207,7 @@ float ControlPotentiometer::distanceBetweenPointAndPoint(Vec2 point1, Vec2 point
{
float dx = point1.x - point2.x;
float dy = point1.y - point2.y;
return sqrt(dx*dx + dy*dy);
return std::sqrt(dx*dx + dy*dy);
}

float ControlPotentiometer::angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint(
Expand All @@ -220,8 +221,8 @@ float ControlPotentiometer::angleInDegreesBetweenLineFromPoint_toPoint_toLineFro
float c = endLineB.x - beginLineB.x;
float d = endLineB.y - beginLineB.y;

float atanA = atan2(a, b);
float atanB = atan2(c, d);
float atanA = std::atan2(a, b);
float atanB = std::atan2(c, d);

// convert radiants to degrees
return (atanA - atanB) * 180 / M_PI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "CCControlSaturationBrightnessPicker.h"
#include <cmath>

NS_CC_EXT_BEGIN

Expand Down Expand Up @@ -154,8 +155,8 @@ void ControlSaturationBrightnessPicker::updateSliderPosition(Vec2 sliderPosition
else if (sliderPosition.y > _startPos.y + boxPos + boxSize) sliderPosition.y = _startPos.y + boxPos + boxSize;

// Use the position / slider width to determine the percentage the dragger is at
_saturation = 1.0f - fabs((_startPos.x + (float)boxPos - sliderPosition.x)/(float)boxSize);
_brightness = fabs((_startPos.y + (float)boxPos - sliderPosition.y)/(float)boxSize);
_saturation = 1.0f - std::fabs((_startPos.x + (float)boxPos - sliderPosition.x)/(float)boxSize);
_brightness = std::fabs((_startPos.y + (float)boxPos - sliderPosition.y)/(float)boxSize);
}

bool ControlSaturationBrightnessPicker::checkSliderPosition(Vec2 location)
Expand Down
Loading