Skip to content
Permalink
Browse files

Add performance checks to clang-tidy

Fix all identified performance issues.
  • Loading branch information
TheCycoONE committed Jan 11, 2020
1 parent ef8f7ef commit 0a822322bce256cee24a4d1f65ed97d088c90316
@@ -1,5 +1,5 @@
---
Checks: 'bugprone-*,-bugprone-suspicious-enum-usage,clang-diagnostic-*,clang-analyzer-*,misc-throw-by-value-catch-by-reference,modernize-use-nullptr,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-override'
Checks: 'bugprone-*,-bugprone-suspicious-enum-usage,clang-diagnostic-*,clang-analyzer-*,misc-throw-by-value-catch-by-reference,modernize-use-nullptr,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-override,performance-*'
WarningsAsErrors: ''
HeaderFilterRegex: '/CorsixTH/Src/|/AnimView/|/common/'
AnalyzeTemporaryDtors: false
@@ -233,7 +233,7 @@ size_t THAnimations::markDuplicates() {
return iNonDuplicateCount;
}

bool THAnimations::loadFrameFile(wxString sFilename) {
bool THAnimations::loadFrameFile(const wxString& sFilename) {
if (!loadVector(frames, sFilename)) return false;

/*
@@ -245,14 +245,14 @@ bool THAnimations::loadFrameFile(wxString sFilename) {
return true;
}

bool THAnimations::loadTableFile(wxString sFilename) {
bool THAnimations::loadTableFile(const wxString& sFilename) {
spriteBitmaps.clear();
if (!loadVector(sprites, sFilename)) return false;
spriteBitmaps.resize(sprites.size());
return true;
}

bool THAnimations::loadPaletteFile(wxString sFilename) {
bool THAnimations::loadPaletteFile(const wxString& sFilename) {
if (!loadVector(colours, sFilename)) return false;
for (th_colour_t& colour : colours) {
colour.r = palette_upscale_map[colour.r & 0x3F];
@@ -262,7 +262,7 @@ bool THAnimations::loadPaletteFile(wxString sFilename) {
return true;
}

bool THAnimations::loadGhostFile(wxString sFilename, int iIndex) {
bool THAnimations::loadGhostFile(const wxString& sFilename, int iIndex) {
if (iIndex < 0 || iIndex >= 4) return false;

std::vector<unsigned char> data;
@@ -285,7 +285,9 @@ size_t THAnimations::getAnimationCount() { return anims.size(); }

size_t THAnimations::getSpriteCount() { return sprites.size(); }

void THAnimations::setSpritePath(wxString aPath) { m_sSpritePath = aPath; }
void THAnimations::setSpritePath(const wxString& aPath) {
m_sSpritePath = aPath;
}

void THAnimations::getAnimationMask(size_t iAnimation, THLayerMask& mskLayers) {
mskLayers.clear();
@@ -155,29 +155,29 @@ class THAnimations {
THAnimations();
~THAnimations() = default;

bool loadAnimationFile(wxString sFilename) {
bool loadAnimationFile(const wxString& sFilename) {
return loadVector(anims, sFilename);
}

bool loadFrameFile(wxString sFilename);
bool loadFrameFile(const wxString& sFilename);

bool loadListFile(wxString sFilename) {
bool loadListFile(const wxString& sFilename) {
return loadVector(elementList, sFilename);
}

bool loadElementFile(wxString sFilename) {
bool loadElementFile(const wxString& sFilename) {
return loadVector(elements, sFilename);
}

bool loadTableFile(wxString sFilename);
bool loadTableFile(const wxString& sFilename);

bool loadSpriteFile(wxString sFilename) {
bool loadSpriteFile(const wxString& sFilename) {
return loadVector(chunks, sFilename);
}

bool loadPaletteFile(wxString sFilename);
bool loadPaletteFile(const wxString& sFilename);

bool loadGhostFile(wxString sFilename, int iIndex);
bool loadGhostFile(const wxString& sFilename, int iIndex);

size_t markDuplicates();

@@ -194,7 +194,7 @@ class THAnimations {
bool isAnimationDuplicate(size_t iAnimation);
bool doesAnimationIncludeFrame(size_t iAnimation, size_t iFrame);
void getAnimationMask(size_t iAnimation, THLayerMask& mskLayers);
void setSpritePath(wxString aPath);
void setSpritePath(const wxString& aPath);

Bitmap* getSpriteBitmap(size_t iSprite, bool bComplex = false);
th_colour_t* getPalette() { return colours.data(); }
@@ -210,7 +210,7 @@ class THAnimations {

protected:
template <class T>
bool loadVector(std::vector<T>& vector, wxString sFilename) {
bool loadVector(std::vector<T>& vector, const wxString& sFilename) {
vector.clear();

wxFile oFile(sFilename);
@@ -237,7 +237,7 @@ class iso_directory_iterator final {
/**
* Move the given iso_directory_iterator
*/
iso_directory_iterator(iso_directory_iterator&& it) {
iso_directory_iterator(iso_directory_iterator&& it) noexcept {
directory_ptr = it.directory_ptr;
end_ptr = it.end_ptr;
entry = std::move(it.entry);
@@ -282,7 +282,7 @@ class iso_directory_iterator final {
/**
* Assign this iterator the value of another iterator by move
*/
iso_directory_iterator& operator=(iso_directory_iterator&& rhs) {
iso_directory_iterator& operator=(iso_directory_iterator&& rhs) noexcept {
directory_ptr = rhs.directory_ptr;
end_ptr = rhs.end_ptr;
entry = std::move(rhs.entry);
@@ -537,7 +537,7 @@ int l_map_getcellflags(lua_State* L) {
}

// Fill Lua table with the flags and numbers of the tile.
for (auto val : lua_tile_flag_map) {
for (const auto& val : lua_tile_flag_map) {
add_cellflag(L, pNode, val.second, val.first);
}
add_cellint(L, pNode->iRoomId, "roomId");
@@ -537,7 +537,7 @@ bool level_map::load_from_th_file(const uint8_t* pData, size_t iDataLength,
return true;
}

void level_map::save(std::string filename) {
void level_map::save(const std::string& filename) {
uint8_t aBuffer[256] = {0};
int iBufferNext = 0;
std::ofstream os(filename, std::ios_base::trunc | std::ios_base::binary);
@@ -240,7 +240,7 @@ class level_map {
map_load_object_callback_fn fnObjectCallback,
void* pCallbackToken);

void save(std::string filename);
void save(const std::string& filename);

//! Set the sprite sheet to be used for drawing the map
/*!
@@ -191,7 +191,7 @@ void map_parcels_overlay::draw_cell(render_target* pCanvas, int iCanvasX,
}

void map_typical_overlay::draw_text(render_target* pCanvas, int iX, int iY,
std::string str) {
const std::string& str) {
text_layout oArea = font->get_text_dimensions(str.c_str(), str.length());
font->draw_text(pCanvas, str.c_str(), str.length(),
iX + (64 - oArea.end_x) / 2, iY + (32 - oArea.end_y) / 2);
@@ -64,7 +64,8 @@ class map_typical_overlay : public map_overlay {
void set_font(::font* font, bool take_ownership);

protected:
void draw_text(render_target* pCanvas, int iX, int iY, std::string str);
void draw_text(render_target* pCanvas, int iX, int iY,
const std::string& str);

sprite_sheet* sprites;
::font* font;
@@ -80,7 +81,7 @@ class map_text_overlay : public map_typical_overlay {
~map_text_overlay() override = default;

void draw_cell(render_target* pCanvas, int iCanvasX, int iCanvasY,
const level_map* pMap, int iNodeX, int iNodeY) override;
const level_map* pMap, int iNodeX, int iNodeY) override;

void set_background_sprite(size_t iSprite);
virtual const std::string get_text(const level_map* pMap, int iNodeX,

0 comments on commit 0a82232

Please sign in to comment.
You can’t perform that action at this time.