Fix various performance issues reported by cppcheck (#5628)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Fri, 21 Apr 2017 08:06:08 +0000 (10:06 +0200)
committerGitHub <noreply@github.com>
Fri, 21 Apr 2017 08:06:08 +0000 (10:06 +0200)
* Also remove 1 non declared but defined functions

src/clientmedia.cpp
src/clientmedia.h
src/guiEngine.cpp
src/guiEngine.h
src/guiFormSpecMenu.h
src/network/connection.cpp
src/network/connection.h
src/settings.h

index bca3f67c28fd721c80fead554074f9c41ac1680d..14a38ca66439dbacfe065b3da3d274251a50b9dd 100644 (file)
@@ -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;
@@ -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
 
@@ -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
 
index 1f0da70d9de456ecc6ad62297a2eabb06cd7f5e5..e292be5ea52314a18d052ae1011f20b684ffc70d 100644 (file)
@@ -58,10 +58,10 @@ public:
        }
 
        // 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()
index e0ee00ad62a8af0d23711817537d925799403fdb..ebc4aac4416e3e9ea9811e4cf45aa66970c33c95 100644 (file)
@@ -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));
 }
@@ -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);
index 98e88574cacae37e42c41f8fc52db2ffcd92032e..e7e5ca05dc30bae22dad0de4ffd7a3df172fd0ed 100644 (file)
@@ -80,7 +80,7 @@ public:
         * 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 */
@@ -260,14 +260,11 @@ private:
         * @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
index 4bc2448d847eb997936c65976ec0e3ff589dc880..ec122b617b0c2167a0d4b42a33e647019cf7ae3b 100644 (file)
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -550,22 +542,19 @@ private:
 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;
 };
index e11b4a953d55f9927044d1f9a85bd138491d53c5..f9a4821a6af752ec18da825f121a836e41ed65f5 100644 (file)
@@ -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) {
@@ -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);
                }
index 7ba0d086ebcd871a939fbd7638f12f332ac94e9e..dc86d22936acef4662c28f24179fad8a524f3a4a 100644 (file)
@@ -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();
index 777d0eff5e3b6f0b1098b0e58f869adab15b29a9..8c4f6e559e05cfedc9f0c21953d947a6b9f80c69 100644 (file)
@@ -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;