Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix various performance issues reported by cppcheck (#5628)
* Also remove 1 non declared but defined functions
  • Loading branch information
nerzhul committed Apr 21, 2017
1 parent de5ecc9 commit 370354c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 77 deletions.
14 changes: 7 additions & 7 deletions src/clientmedia.cpp
Expand Up @@ -42,12 +42,12 @@ static std::string getMediaCacheDir()
*/

ClientMediaDownloader::ClientMediaDownloader():
m_media_cache(getMediaCacheDir())
m_media_cache(getMediaCacheDir()),
m_initial_step_done(false),
m_uncached_count(0),
m_uncached_received_count(0),
m_name_bound("")
{
m_initial_step_done = false;
m_name_bound = ""; // works because "" is an invalid file name
m_uncached_count = 0;
m_uncached_received_count = 0;
m_httpfetch_caller = HTTPFETCH_DISCARD;
m_httpfetch_active = 0;
m_httpfetch_active_limit = 0;
Expand All @@ -69,7 +69,7 @@ ClientMediaDownloader::~ClientMediaDownloader()
delete m_remotes[i];
}

void ClientMediaDownloader::addFile(std::string name, std::string sha1)
void ClientMediaDownloader::addFile(const std::string &name, const std::string &sha1)
{
assert(!m_initial_step_done); // pre-condition

Expand Down Expand Up @@ -104,7 +104,7 @@ void ClientMediaDownloader::addFile(std::string name, std::string sha1)
m_files.insert(std::make_pair(name, filestatus));
}

void ClientMediaDownloader::addRemoteServer(std::string baseurl)
void ClientMediaDownloader::addRemoteServer(const std::string &baseurl)
{
assert(!m_initial_step_done); // pre-condition

Expand Down
4 changes: 2 additions & 2 deletions src/clientmedia.h
Expand Up @@ -58,10 +58,10 @@ class ClientMediaDownloader
}

// Add a file to the list of required file (but don't fetch it yet)
void addFile(std::string name, std::string sha1);
void addFile(const std::string &name, const std::string &sha1);

// Add a remote server to the list; ignored if not built with cURL
void addRemoteServer(std::string baseurl);
void addRemoteServer(const std::string &baseurl);

// Steps the media downloader:
// - May load media into client by calling client->loadMedia()
Expand Down
4 changes: 2 additions & 2 deletions src/guiEngine.cpp
Expand Up @@ -60,7 +60,7 @@ void TextDestGuiEngine::gotText(const StringMap &fields)
}

/******************************************************************************/
void TextDestGuiEngine::gotText(std::wstring text)
void TextDestGuiEngine::gotText(const std::wstring &text)
{
m_engine->getScriptIface()->handleMainMenuEvent(wide_to_utf8(text));
}
Expand Down Expand Up @@ -540,7 +540,7 @@ bool GUIEngine::setTexture(texture_layer layer, std::string texturepath,
}

/******************************************************************************/
bool GUIEngine::downloadFile(std::string url, std::string target)
bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
{
#if USE_CURL
std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
Expand Down
7 changes: 2 additions & 5 deletions src/guiEngine.h
Expand Up @@ -80,7 +80,7 @@ class TextDestGuiEngine : public TextDest
* receive text/events transmitted by guiFormSpecMenu
* @param text textual representation of event
*/
void gotText(std::wstring text);
void gotText(const std::wstring &text);

private:
/** target to transmit data to */
Expand Down Expand Up @@ -260,14 +260,11 @@ class GUIEngine {
* @param url url to download
* @param target file to store to
*/
static bool downloadFile(std::string url,std::string target);
static bool downloadFile(const std::string &url, const std::string &target);

/** array containing pointers to current specified texture layers */
image_definition m_textures[TEX_LAYER_MAX];

/** draw version string in topleft corner */
void drawVersion();

/**
* specify text to appear as top left string
* @param text to set
Expand Down
65 changes: 27 additions & 38 deletions src/guiFormSpecMenu.h
Expand Up @@ -78,22 +78,19 @@ class GUIFormSpecMenu : public GUIModalMenu
{
struct ItemSpec
{
ItemSpec()
{
i = -1;
}
ItemSpec() :
i(-1)
{}

ItemSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname,
s32 a_i)
{
inventoryloc = a_inventoryloc;
listname = a_listname;
i = a_i;
}
bool isValid() const
{
return i != -1;
}
s32 a_i) :
inventoryloc(a_inventoryloc),
listname(a_listname),
i(a_i)
{}

bool isValid() const { return i != -1; }

InventoryLocation inventoryloc;
std::string listname;
Expand Down Expand Up @@ -208,14 +205,13 @@ class GUIFormSpecMenu : public GUIModalMenu
const std::wstring &default_text, int id) :
fname(name),
flabel(label),
fdefault(unescape_enriched(default_text)),
fid(id),
send(false),
ftype(f_Unknown),
is_exit(false)
{
//flabel = unescape_enriched(label);
fdefault = unescape_enriched(default_text);
}
{}

std::string fname;
std::wstring flabel;
std::wstring fdefault;
Expand All @@ -239,17 +235,14 @@ class GUIFormSpecMenu : public GUIModalMenu
};

struct TooltipSpec {
TooltipSpec()
{
}
TooltipSpec() {}
TooltipSpec(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)
{
//tooltip = unescape_enriched(utf8_to_wide(a_tooltip));
tooltip = utf8_to_wide(a_tooltip);
}
{}

std::wstring tooltip;
irr::video::SColor bgcolor;
irr::video::SColor color;
Expand All @@ -271,12 +264,11 @@ class GUIFormSpecMenu : public GUIModalMenu
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)
{
//text = unescape_enriched(a_text);
text = a_text;
}
{}

std::wstring text;
core::rect<s32> rect;
gui::IGUIButton *parent_button;
Expand Down Expand Up @@ -550,22 +542,19 @@ class GUIFormSpecMenu : public GUIModalMenu
class FormspecFormSource: public IFormSource
{
public:
FormspecFormSource(const std::string &formspec)
{
m_formspec = formspec;
}
FormspecFormSource(const std::string &formspec):
m_formspec(formspec)
{}

~FormspecFormSource()
{}

void setForm(const std::string &formspec) {
void setForm(const std::string &formspec)
{
m_formspec = FORMSPEC_VERSION_STRING + formspec;
}

std::string getForm()
{
return m_formspec;
}
std::string getForm() { return m_formspec; }

std::string m_formspec;
};
Expand Down
5 changes: 2 additions & 3 deletions src/network/connection.cpp
Expand Up @@ -930,7 +930,7 @@ void Peer::DecUseCount()
delete this;
}

void Peer::RTTStatistics(float rtt, std::string profiler_id,
void Peer::RTTStatistics(float rtt, const std::string &profiler_id,
unsigned int num_samples) {

if (m_last_rtt > 0) {
Expand Down Expand Up @@ -969,8 +969,7 @@ void Peer::RTTStatistics(float rtt, std::string profiler_id,
m_rtt.jitter_avg = m_rtt.jitter_avg * (num_samples/(num_samples-1)) +
jitter * (1/num_samples);

if (profiler_id != "")
{
if (profiler_id != "") {
g_profiler->graphAdd(profiler_id + "_rtt", rtt);
g_profiler->graphAdd(profiler_id + "_jitter", jitter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/network/connection.h
Expand Up @@ -732,8 +732,8 @@ class Peer {
virtual void reportRTT(float rtt) {};

void RTTStatistics(float rtt,
std::string profiler_id="",
unsigned int num_samples=1000);
const std::string &profiler_id = "",
unsigned int num_samples = 1000);

bool IncUseCount();
void DecUseCount();
Expand Down
33 changes: 15 additions & 18 deletions src/settings.h
Expand Up @@ -74,24 +74,21 @@ struct ValueSpec {
};

struct SettingsEntry {
SettingsEntry()
{
group = NULL;
is_group = false;
}

SettingsEntry(const std::string &value_)
{
value = value_;
group = NULL;
is_group = false;
}

SettingsEntry(Settings *group_)
{
group = group_;
is_group = true;
}
SettingsEntry() :
group(NULL),
is_group(false)
{}

SettingsEntry(const std::string &value_) :
value(value_),
group(NULL),
is_group(false)
{}

SettingsEntry(Settings *group_) :
group(group_),
is_group(true)
{}

std::string value;
Settings *group;
Expand Down

0 comments on commit 370354c

Please sign in to comment.