aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-04-21 23:40:48 +0200
committerGitHub <noreply@github.com>2017-04-21 23:40:48 +0200
commitdc0e9097d3144a3dda81039f666ee43ba29cbc36 (patch)
tree25f9db4f6357826bfb5456a642b522bb0b235d6f /src
parentf151b2322003bbc89c2cd3c603ef1e1ab9d46439 (diff)
downloadminetest-dc0e9097d3144a3dda81039f666ee43ba29cbc36.tar.gz
minetest-dc0e9097d3144a3dda81039f666ee43ba29cbc36.tar.bz2
minetest-dc0e9097d3144a3dda81039f666ee43ba29cbc36.zip
Fix various performance issues reported by cppcheck + code style (CI) (#5635)
* Make CI happy with code style on master * guiFileSelectMenu: remove useless includes * some performance fixes pointed by cppcheck * remove some useless casts * TextDest: remove unused setFormSpec function
Diffstat (limited to 'src')
-rw-r--r--src/guiFileSelectMenu.cpp22
-rw-r--r--src/guiFileSelectMenu.h7
-rw-r--r--src/guiFormSpecMenu.cpp5
-rw-r--r--src/guiFormSpecMenu.h60
-rw-r--r--src/mesh.cpp10
-rw-r--r--src/sound.h8
-rw-r--r--src/wieldmesh.h25
7 files changed, 70 insertions, 67 deletions
diff --git a/src/guiFileSelectMenu.cpp b/src/guiFileSelectMenu.cpp
index 0bb02f8a6..89d34a307 100644
--- a/src/guiFileSelectMenu.cpp
+++ b/src/guiFileSelectMenu.cpp
@@ -18,19 +18,17 @@
*/
#include "guiFileSelectMenu.h"
-#include "util/string.h"
-#include <locale.h>
GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
- gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
- std::string title, std::string formname) :
-GUIModalMenu(env, parent, id, menumgr)
+ gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
+ const std::string &title, const std::string &formname) :
+ GUIModalMenu(env, parent, id, menumgr),
+ m_title(utf8_to_wide(title)),
+ m_accepted(false),
+ m_parent(parent),
+ m_text_dst(NULL),
+ m_formname(formname)
{
- m_title = utf8_to_wide(title);
- m_parent = parent;
- m_formname = formname;
- m_text_dst = 0;
- m_accepted = false;
}
GUIFileSelectMenu::~GUIFileSelectMenu()
@@ -107,16 +105,12 @@ bool GUIFileSelectMenu::OnEvent(const SEvent& event)
acceptInput();
quitMenu();
return true;
- break;
-
case gui::EGET_DIRECTORY_SELECTED:
case gui::EGET_FILE_SELECTED:
m_accepted=true;
acceptInput();
quitMenu();
return true;
- break;
-
default:
//ignore this event
break;
diff --git a/src/guiFileSelectMenu.h b/src/guiFileSelectMenu.h
index e37d3d8df..a266cb399 100644
--- a/src/guiFileSelectMenu.h
+++ b/src/guiFileSelectMenu.h
@@ -32,8 +32,7 @@ class GUIFileSelectMenu: public GUIModalMenu
public:
GUIFileSelectMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent,
s32 id, IMenuManager *menumgr,
- std::string title,
- std::string formid);
+ const std::string &title, const std::string &formid);
~GUIFileSelectMenu();
void removeChildren();
@@ -47,9 +46,7 @@ public:
bool OnEvent(const SEvent& event);
- bool isRunning() {
- return m_running;
- }
+ bool isRunning() const { return m_running; }
void setTextDest(TextDest * dest) {
m_text_dst = dest;
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp
index ab93aeca1..5861e9a81 100644
--- a/src/guiFormSpecMenu.cpp
+++ b/src/guiFormSpecMenu.cpp
@@ -1770,10 +1770,11 @@ void GUIFormSpecMenu::parseAnchor(parserData *data, const std::string &element)
return;
}
- errorstream << "Invalid anchor element (" << parts.size() << "): '" << element << "'" << std::endl;
+ errorstream << "Invalid anchor element (" << parts.size() << "): '" << element
+ << "'" << std::endl;
}
-void GUIFormSpecMenu::parseElement(parserData* data, std::string element)
+void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
{
//some prechecks
if (element == "")
diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h
index ec122b617..d70c3a582 100644
--- a/src/guiFormSpecMenu.h
+++ b/src/guiFormSpecMenu.h
@@ -55,12 +55,10 @@ typedef enum {
struct TextDest
{
- virtual ~TextDest() {};
+ virtual ~TextDest() {}
// This is deprecated I guess? -celeron55
virtual void gotText(std::wstring text){}
virtual void gotText(const StringMap &fields) = 0;
- virtual void setFormName(std::string formname)
- { m_formname = formname;};
std::string m_formname;
};
@@ -80,7 +78,8 @@ class GUIFormSpecMenu : public GUIModalMenu
{
ItemSpec() :
i(-1)
- {}
+ {
+ }
ItemSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname,
@@ -88,7 +87,8 @@ class GUIFormSpecMenu : public GUIModalMenu
inventoryloc(a_inventoryloc),
listname(a_listname),
i(a_i)
- {}
+ {
+ }
bool isValid() const { return i != -1; }
@@ -141,7 +141,8 @@ class GUIFormSpecMenu : public GUIModalMenu
ImageDrawSpec():
parent_button(NULL),
clip(false)
- {}
+ {
+ }
ImageDrawSpec(const std::string &a_name,
const std::string &a_item_name,
@@ -154,7 +155,8 @@ class GUIFormSpecMenu : public GUIModalMenu
geom(a_geom),
scale(true),
clip(false)
- {}
+ {
+ }
ImageDrawSpec(const std::string &a_name,
const std::string &a_item_name,
@@ -166,7 +168,8 @@ class GUIFormSpecMenu : public GUIModalMenu
geom(a_geom),
scale(true),
clip(false)
- {}
+ {
+ }
ImageDrawSpec(const std::string &a_name,
const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false):
@@ -176,7 +179,8 @@ class GUIFormSpecMenu : public GUIModalMenu
geom(a_geom),
scale(true),
clip(clip)
- {}
+ {
+ }
ImageDrawSpec(const std::string &a_name,
const v2s32 &a_pos):
@@ -185,7 +189,8 @@ class GUIFormSpecMenu : public GUIModalMenu
pos(a_pos),
scale(false),
clip(false)
- {}
+ {
+ }
std::string name;
std::string item_name;
@@ -210,7 +215,8 @@ class GUIFormSpecMenu : public GUIModalMenu
send(false),
ftype(f_Unknown),
is_exit(false)
- {}
+ {
+ }
std::string fname;
std::wstring flabel;
@@ -222,7 +228,8 @@ class GUIFormSpecMenu : public GUIModalMenu
core::rect<s32> rect;
};
- struct BoxDrawSpec {
+ struct BoxDrawSpec
+ {
BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
pos(a_pos),
geom(a_geom),
@@ -234,40 +241,45 @@ class GUIFormSpecMenu : public GUIModalMenu
irr::video::SColor color;
};
- struct TooltipSpec {
+ struct TooltipSpec
+ {
TooltipSpec() {}
- TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor,
+ TooltipSpec(const std::string &a_tooltip, irr::video::SColor a_bgcolor,
irr::video::SColor a_color):
tooltip(utf8_to_wide(a_tooltip)),
bgcolor(a_bgcolor),
color(a_color)
- {}
+ {
+ }
std::wstring tooltip;
irr::video::SColor bgcolor;
irr::video::SColor color;
};
- struct StaticTextSpec {
+ struct StaticTextSpec
+ {
StaticTextSpec():
parent_button(NULL)
{
}
+
StaticTextSpec(const std::wstring &a_text,
const core::rect<s32> &a_rect):
+ text(a_text),
rect(a_rect),
parent_button(NULL)
{
- //text = unescape_enriched(a_text);
- text = a_text;
}
+
StaticTextSpec(const std::wstring &a_text,
const core::rect<s32> &a_rect,
gui::IGUIButton *a_parent_button):
text(a_text),
rect(a_rect),
parent_button(a_parent_button)
- {}
+ {
+ }
std::wstring text;
core::rect<s32> rect;
@@ -288,7 +300,7 @@ public:
~GUIFormSpecMenu();
void setFormSpec(const std::string &formspec_string,
- InventoryLocation current_inventory_location)
+ const InventoryLocation &current_inventory_location)
{
m_formspec_string = formspec_string;
m_current_inventory_location = current_inventory_location;
@@ -461,7 +473,7 @@ private:
fs_key_pendig current_keys_pending;
std::string current_field_enter_pending;
- void parseElement(parserData* data, std::string element);
+ void parseElement(parserData* data, const std::string &element);
void parseSize(parserData* data, const std::string &element);
void parseContainer(parserData* data, const std::string &element);
@@ -544,10 +556,12 @@ class FormspecFormSource: public IFormSource
public:
FormspecFormSource(const std::string &formspec):
m_formspec(formspec)
- {}
+ {
+ }
~FormspecFormSource()
- {}
+ {
+ }
void setForm(const std::string &formspec)
{
diff --git a/src/mesh.cpp b/src/mesh.cpp
index d776f6185..0a5b7fb6c 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -391,7 +391,7 @@ scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
switch (mesh_buffer->getVertexType()) {
case video::EVT_STANDARD: {
video::S3DVertex *v = (video::S3DVertex *) mesh_buffer->getVertices();
- u16 *indices = (u16*) mesh_buffer->getIndices();
+ u16 *indices = mesh_buffer->getIndices();
scene::SMeshBuffer *temp_buf = new scene::SMeshBuffer();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount());
@@ -401,7 +401,7 @@ scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
case video::EVT_2TCOORDS: {
video::S3DVertex2TCoords *v =
(video::S3DVertex2TCoords *) mesh_buffer->getVertices();
- u16 *indices = (u16*) mesh_buffer->getIndices();
+ u16 *indices = mesh_buffer->getIndices();
scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount());
@@ -410,7 +410,7 @@ scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
case video::EVT_TANGENTS: {
video::S3DVertexTangents *v =
(video::S3DVertexTangents *) mesh_buffer->getVertices();
- u16 *indices = (u16*) mesh_buffer->getIndices();
+ u16 *indices = mesh_buffer->getIndices();
scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount());
@@ -447,7 +447,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
buf->drop();
}
- video::SColor c(255,255,255,255);
+ video::SColor c(255,255,255,255);
for (std::vector<aabb3f>::const_iterator
i = boxes.begin();
@@ -534,7 +534,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
buf->append(vertices + j, 4, indices, 6);
}
}
- return dst_mesh;
+ return dst_mesh;
}
struct vcache
diff --git a/src/sound.h b/src/sound.h
index d13799eac..98f7692d5 100644
--- a/src/sound.h
+++ b/src/sound.h
@@ -34,10 +34,10 @@ public:
struct SimpleSoundSpec
{
- SimpleSoundSpec(const std::string &name = "", float gain = 1.0) :
- name(name),
- gain(gain)
- {}
+ SimpleSoundSpec(const std::string &name = "", float gain = 1.0)
+ : name(name), gain(gain)
+ {
+ }
bool exists() const { return name != ""; }
diff --git a/src/wieldmesh.h b/src/wieldmesh.h
index c98b469d9..ef164c11f 100644
--- a/src/wieldmesh.h
+++ b/src/wieldmesh.h
@@ -31,7 +31,8 @@ struct ContentFeatures;
/*!
* Holds color information of an item mesh's buffer.
*/
-struct ItemPartColor {
+struct ItemPartColor
+{
/*!
* If this is false, the global base color of the item
* will be used instead of the specific color of the
@@ -43,15 +44,12 @@ struct ItemPartColor {
*/
video::SColor color;
- ItemPartColor():
- override_base(false),
- color(0)
- {}
+ ItemPartColor() : override_base(false), color(0) {}
- ItemPartColor(bool override, video::SColor color):
- override_base(override),
- color(color)
- {}
+ ItemPartColor(bool override, video::SColor color)
+ : override_base(override), color(color)
+ {
+ }
};
struct ItemMesh
@@ -75,8 +73,7 @@ public:
s32 id = -1, bool lighting = false);
virtual ~WieldMeshSceneNode();
- void setCube(const ContentFeatures &f, v3f wield_scale,
- ITextureSource *tsrc);
+ void setCube(const ContentFeatures &f, v3f wield_scale, ITextureSource *tsrc);
void setExtruded(const std::string &imagename, v3f wield_scale,
ITextureSource *tsrc, u8 num_frames);
void setItem(const ItemStack &item, Client *client);
@@ -133,7 +130,7 @@ scene::SMesh *getExtrudedMesh(ITextureSource *tsrc, const std::string &imagename
* be NULL to leave the original material.
* \param colors returns the colors of the mesh buffers in the mesh.
*/
-void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f,
- bool use_shaders, bool set_material, video::E_MATERIAL_TYPE *mattype,
- std::vector<ItemPartColor> *colors);
+void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders,
+ bool set_material, video::E_MATERIAL_TYPE *mattype,
+ std::vector<ItemPartColor> *colors);
#endif