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
master
Loïc Blot 2017-04-21 23:40:48 +02:00 committed by GitHub
parent f151b23220
commit dc0e9097d3
7 changed files with 70 additions and 67 deletions

View File

@ -18,19 +18,17 @@
*/ */
#include "guiFileSelectMenu.h" #include "guiFileSelectMenu.h"
#include "util/string.h"
#include <locale.h>
GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env, GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
std::string title, std::string formname) : const std::string &title, const std::string &formname) :
GUIModalMenu(env, parent, id, menumgr) 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() GUIFileSelectMenu::~GUIFileSelectMenu()
@ -107,16 +105,12 @@ bool GUIFileSelectMenu::OnEvent(const SEvent& event)
acceptInput(); acceptInput();
quitMenu(); quitMenu();
return true; return true;
break;
case gui::EGET_DIRECTORY_SELECTED: case gui::EGET_DIRECTORY_SELECTED:
case gui::EGET_FILE_SELECTED: case gui::EGET_FILE_SELECTED:
m_accepted=true; m_accepted=true;
acceptInput(); acceptInput();
quitMenu(); quitMenu();
return true; return true;
break;
default: default:
//ignore this event //ignore this event
break; break;

View File

@ -32,8 +32,7 @@ class GUIFileSelectMenu: public GUIModalMenu
public: public:
GUIFileSelectMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, GUIFileSelectMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent,
s32 id, IMenuManager *menumgr, s32 id, IMenuManager *menumgr,
std::string title, const std::string &title, const std::string &formid);
std::string formid);
~GUIFileSelectMenu(); ~GUIFileSelectMenu();
void removeChildren(); void removeChildren();
@ -47,9 +46,7 @@ public:
bool OnEvent(const SEvent& event); bool OnEvent(const SEvent& event);
bool isRunning() { bool isRunning() const { return m_running; }
return m_running;
}
void setTextDest(TextDest * dest) { void setTextDest(TextDest * dest) {
m_text_dst = dest; m_text_dst = dest;

View File

@ -1770,10 +1770,11 @@ void GUIFormSpecMenu::parseAnchor(parserData *data, const std::string &element)
return; 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 //some prechecks
if (element == "") if (element == "")

View File

@ -55,12 +55,10 @@ typedef enum {
struct TextDest struct TextDest
{ {
virtual ~TextDest() {}; virtual ~TextDest() {}
// This is deprecated I guess? -celeron55 // This is deprecated I guess? -celeron55
virtual void gotText(std::wstring text){} virtual void gotText(std::wstring text){}
virtual void gotText(const StringMap &fields) = 0; virtual void gotText(const StringMap &fields) = 0;
virtual void setFormName(std::string formname)
{ m_formname = formname;};
std::string m_formname; std::string m_formname;
}; };
@ -80,7 +78,8 @@ class GUIFormSpecMenu : public GUIModalMenu
{ {
ItemSpec() : ItemSpec() :
i(-1) i(-1)
{} {
}
ItemSpec(const InventoryLocation &a_inventoryloc, ItemSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname, const std::string &a_listname,
@ -88,7 +87,8 @@ class GUIFormSpecMenu : public GUIModalMenu
inventoryloc(a_inventoryloc), inventoryloc(a_inventoryloc),
listname(a_listname), listname(a_listname),
i(a_i) i(a_i)
{} {
}
bool isValid() const { return i != -1; } bool isValid() const { return i != -1; }
@ -141,7 +141,8 @@ class GUIFormSpecMenu : public GUIModalMenu
ImageDrawSpec(): ImageDrawSpec():
parent_button(NULL), parent_button(NULL),
clip(false) clip(false)
{} {
}
ImageDrawSpec(const std::string &a_name, ImageDrawSpec(const std::string &a_name,
const std::string &a_item_name, const std::string &a_item_name,
@ -154,7 +155,8 @@ class GUIFormSpecMenu : public GUIModalMenu
geom(a_geom), geom(a_geom),
scale(true), scale(true),
clip(false) clip(false)
{} {
}
ImageDrawSpec(const std::string &a_name, ImageDrawSpec(const std::string &a_name,
const std::string &a_item_name, const std::string &a_item_name,
@ -166,7 +168,8 @@ class GUIFormSpecMenu : public GUIModalMenu
geom(a_geom), geom(a_geom),
scale(true), scale(true),
clip(false) clip(false)
{} {
}
ImageDrawSpec(const std::string &a_name, ImageDrawSpec(const std::string &a_name,
const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false): const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false):
@ -176,7 +179,8 @@ class GUIFormSpecMenu : public GUIModalMenu
geom(a_geom), geom(a_geom),
scale(true), scale(true),
clip(clip) clip(clip)
{} {
}
ImageDrawSpec(const std::string &a_name, ImageDrawSpec(const std::string &a_name,
const v2s32 &a_pos): const v2s32 &a_pos):
@ -185,7 +189,8 @@ class GUIFormSpecMenu : public GUIModalMenu
pos(a_pos), pos(a_pos),
scale(false), scale(false),
clip(false) clip(false)
{} {
}
std::string name; std::string name;
std::string item_name; std::string item_name;
@ -210,7 +215,8 @@ class GUIFormSpecMenu : public GUIModalMenu
send(false), send(false),
ftype(f_Unknown), ftype(f_Unknown),
is_exit(false) is_exit(false)
{} {
}
std::string fname; std::string fname;
std::wstring flabel; std::wstring flabel;
@ -222,7 +228,8 @@ class GUIFormSpecMenu : public GUIModalMenu
core::rect<s32> rect; core::rect<s32> rect;
}; };
struct BoxDrawSpec { struct BoxDrawSpec
{
BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color): BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
pos(a_pos), pos(a_pos),
geom(a_geom), geom(a_geom),
@ -234,40 +241,45 @@ class GUIFormSpecMenu : public GUIModalMenu
irr::video::SColor color; irr::video::SColor color;
}; };
struct TooltipSpec { struct TooltipSpec
{
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): irr::video::SColor a_color):
tooltip(utf8_to_wide(a_tooltip)), tooltip(utf8_to_wide(a_tooltip)),
bgcolor(a_bgcolor), bgcolor(a_bgcolor),
color(a_color) color(a_color)
{} {
}
std::wstring tooltip; std::wstring tooltip;
irr::video::SColor bgcolor; irr::video::SColor bgcolor;
irr::video::SColor color; irr::video::SColor color;
}; };
struct StaticTextSpec { struct StaticTextSpec
{
StaticTextSpec(): StaticTextSpec():
parent_button(NULL) parent_button(NULL)
{ {
} }
StaticTextSpec(const std::wstring &a_text, StaticTextSpec(const std::wstring &a_text,
const core::rect<s32> &a_rect): const core::rect<s32> &a_rect):
text(a_text),
rect(a_rect), rect(a_rect),
parent_button(NULL) parent_button(NULL)
{ {
//text = unescape_enriched(a_text);
text = a_text;
} }
StaticTextSpec(const std::wstring &a_text, StaticTextSpec(const std::wstring &a_text,
const core::rect<s32> &a_rect, const core::rect<s32> &a_rect,
gui::IGUIButton *a_parent_button): gui::IGUIButton *a_parent_button):
text(a_text), text(a_text),
rect(a_rect), rect(a_rect),
parent_button(a_parent_button) parent_button(a_parent_button)
{} {
}
std::wstring text; std::wstring text;
core::rect<s32> rect; core::rect<s32> rect;
@ -288,7 +300,7 @@ public:
~GUIFormSpecMenu(); ~GUIFormSpecMenu();
void setFormSpec(const std::string &formspec_string, void setFormSpec(const std::string &formspec_string,
InventoryLocation current_inventory_location) const InventoryLocation &current_inventory_location)
{ {
m_formspec_string = formspec_string; m_formspec_string = formspec_string;
m_current_inventory_location = current_inventory_location; m_current_inventory_location = current_inventory_location;
@ -461,7 +473,7 @@ private:
fs_key_pendig current_keys_pending; fs_key_pendig current_keys_pending;
std::string current_field_enter_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 parseSize(parserData* data, const std::string &element);
void parseContainer(parserData* data, const std::string &element); void parseContainer(parserData* data, const std::string &element);
@ -544,10 +556,12 @@ class FormspecFormSource: public IFormSource
public: public:
FormspecFormSource(const std::string &formspec): FormspecFormSource(const std::string &formspec):
m_formspec(formspec) m_formspec(formspec)
{} {
}
~FormspecFormSource() ~FormspecFormSource()
{} {
}
void setForm(const std::string &formspec) void setForm(const std::string &formspec)
{ {

View File

@ -391,7 +391,7 @@ scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
switch (mesh_buffer->getVertexType()) { switch (mesh_buffer->getVertexType()) {
case video::EVT_STANDARD: { case video::EVT_STANDARD: {
video::S3DVertex *v = (video::S3DVertex *) mesh_buffer->getVertices(); 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(); scene::SMeshBuffer *temp_buf = new scene::SMeshBuffer();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices, temp_buf->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount()); mesh_buffer->getIndexCount());
@ -401,7 +401,7 @@ scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
case video::EVT_2TCOORDS: { case video::EVT_2TCOORDS: {
video::S3DVertex2TCoords *v = video::S3DVertex2TCoords *v =
(video::S3DVertex2TCoords *) mesh_buffer->getVertices(); (video::S3DVertex2TCoords *) mesh_buffer->getVertices();
u16 *indices = (u16*) mesh_buffer->getIndices(); u16 *indices = mesh_buffer->getIndices();
scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents(); scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices, temp_buf->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount()); mesh_buffer->getIndexCount());
@ -410,7 +410,7 @@ scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
case video::EVT_TANGENTS: { case video::EVT_TANGENTS: {
video::S3DVertexTangents *v = video::S3DVertexTangents *v =
(video::S3DVertexTangents *) mesh_buffer->getVertices(); (video::S3DVertexTangents *) mesh_buffer->getVertices();
u16 *indices = (u16*) mesh_buffer->getIndices(); u16 *indices = mesh_buffer->getIndices();
scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents(); scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices, temp_buf->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount()); mesh_buffer->getIndexCount());
@ -447,7 +447,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
buf->drop(); buf->drop();
} }
video::SColor c(255,255,255,255); video::SColor c(255,255,255,255);
for (std::vector<aabb3f>::const_iterator for (std::vector<aabb3f>::const_iterator
i = boxes.begin(); i = boxes.begin();
@ -534,7 +534,7 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
buf->append(vertices + j, 4, indices, 6); buf->append(vertices + j, 4, indices, 6);
} }
} }
return dst_mesh; return dst_mesh;
} }
struct vcache struct vcache

View File

@ -34,10 +34,10 @@ public:
struct SimpleSoundSpec struct SimpleSoundSpec
{ {
SimpleSoundSpec(const std::string &name = "", float gain = 1.0) : SimpleSoundSpec(const std::string &name = "", float gain = 1.0)
name(name), : name(name), gain(gain)
gain(gain) {
{} }
bool exists() const { return name != ""; } bool exists() const { return name != ""; }

View File

@ -31,7 +31,8 @@ struct ContentFeatures;
/*! /*!
* Holds color information of an item mesh's buffer. * Holds color information of an item mesh's buffer.
*/ */
struct ItemPartColor { struct ItemPartColor
{
/*! /*!
* If this is false, the global base color of the item * If this is false, the global base color of the item
* will be used instead of the specific color of the * will be used instead of the specific color of the
@ -43,15 +44,12 @@ struct ItemPartColor {
*/ */
video::SColor color; video::SColor color;
ItemPartColor(): ItemPartColor() : override_base(false), color(0) {}
override_base(false),
color(0)
{}
ItemPartColor(bool override, video::SColor color): ItemPartColor(bool override, video::SColor color)
override_base(override), : override_base(override), color(color)
color(color) {
{} }
}; };
struct ItemMesh struct ItemMesh
@ -75,8 +73,7 @@ public:
s32 id = -1, bool lighting = false); s32 id = -1, bool lighting = false);
virtual ~WieldMeshSceneNode(); virtual ~WieldMeshSceneNode();
void setCube(const ContentFeatures &f, v3f wield_scale, void setCube(const ContentFeatures &f, v3f wield_scale, ITextureSource *tsrc);
ITextureSource *tsrc);
void setExtruded(const std::string &imagename, v3f wield_scale, void setExtruded(const std::string &imagename, v3f wield_scale,
ITextureSource *tsrc, u8 num_frames); ITextureSource *tsrc, u8 num_frames);
void setItem(const ItemStack &item, Client *client); 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. * be NULL to leave the original material.
* \param colors returns the colors of the mesh buffers in the mesh. * \param colors returns the colors of the mesh buffers in the mesh.
*/ */
void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, void postProcessNodeMesh(scene::SMesh *mesh, const ContentFeatures &f, bool use_shaders,
bool use_shaders, bool set_material, video::E_MATERIAL_TYPE *mattype, bool set_material, video::E_MATERIAL_TYPE *mattype,
std::vector<ItemPartColor> *colors); std::vector<ItemPartColor> *colors);
#endif #endif