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
This commit is contained in:
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

@ -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;

@ -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;

@ -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 == "")

@ -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)
{

@ -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

@ -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 != ""; }

@ -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