mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-10-31 07:25:22 +01:00 
			
		
		
		
	Fix various performance issues reported by cppcheck (#5628)
* Also remove 1 non declared but defined functions
This commit is contained in:
		| @@ -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
 | ||||
| 
 | ||||
|   | ||||
| @@ -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()
 | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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; | ||||
| }; | ||||
|   | ||||
| @@ -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); | ||||
| 		} | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -74,24 +74,21 @@ struct ValueSpec { | ||||
| }; | ||||
| 
 | ||||
| struct SettingsEntry { | ||||
| 	SettingsEntry() | ||||
| 	{ | ||||
| 		group    = NULL; | ||||
| 		is_group = false; | ||||
| 	} | ||||
| 	SettingsEntry() : | ||||
| 		group(NULL), | ||||
| 		is_group(false) | ||||
| 	{} | ||||
| 
 | ||||
| 	SettingsEntry(const std::string &value_) | ||||
| 	{ | ||||
| 		value    = value_; | ||||
| 		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(Settings *group_) : | ||||
| 		group(group_), | ||||
| 		is_group(true) | ||||
| 	{} | ||||
| 
 | ||||
| 	std::string value; | ||||
| 	Settings *group; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user