mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 08:28:36 +02:00
Fix various points reported by cppcheck (#5656)
* Fix various performance issues reported by cppcheck + code style (CI) * 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 * Fix various iterator post-increment reported by cppcheck
This commit is contained in:
parent
af96309621
commit
a7e131f53e
@ -202,7 +202,8 @@ public:
|
|||||||
|
|
||||||
return meta->getString("formspec");
|
return meta->getString("formspec");
|
||||||
}
|
}
|
||||||
std::string resolveText(std::string str)
|
|
||||||
|
virtual std::string resolveText(const std::string &str)
|
||||||
{
|
{
|
||||||
NodeMetadata *meta = m_map->getNodeMetadata(m_p);
|
NodeMetadata *meta = m_map->getNodeMetadata(m_p);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
virtual ~IFormSource(){}
|
virtual ~IFormSource(){}
|
||||||
virtual std::string getForm() = 0;
|
virtual std::string getForm() = 0;
|
||||||
// Fill in variables in field text
|
// Fill in variables in field text
|
||||||
virtual std::string resolveText(std::string str){ return str; }
|
virtual std::string resolveText(const std::string &str) { return str; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class GUIFormSpecMenu : public GUIModalMenu
|
class GUIFormSpecMenu : public GUIModalMenu
|
||||||
|
@ -25,14 +25,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "map_settings_manager.h"
|
#include "map_settings_manager.h"
|
||||||
|
|
||||||
MapSettingsManager::MapSettingsManager(
|
MapSettingsManager::MapSettingsManager(Settings *user_settings,
|
||||||
Settings *user_settings, const std::string &map_meta_path)
|
const std::string &map_meta_path):
|
||||||
|
mapgen_params(NULL),
|
||||||
|
m_map_meta_path(map_meta_path),
|
||||||
|
m_map_settings(new Settings()),
|
||||||
|
m_user_settings(user_settings)
|
||||||
{
|
{
|
||||||
m_map_meta_path = map_meta_path;
|
|
||||||
m_user_settings = user_settings;
|
|
||||||
m_map_settings = new Settings;
|
|
||||||
mapgen_params = NULL;
|
|
||||||
|
|
||||||
assert(m_user_settings != NULL);
|
assert(m_user_settings != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1318,22 +1318,21 @@ void CNodeDefManager::removeNode(const std::string &name)
|
|||||||
|
|
||||||
// Erase node content from all groups it belongs to
|
// Erase node content from all groups it belongs to
|
||||||
for (UNORDERED_MAP<std::string, GroupItems>::iterator iter_groups =
|
for (UNORDERED_MAP<std::string, GroupItems>::iterator iter_groups =
|
||||||
m_group_to_items.begin();
|
m_group_to_items.begin(); iter_groups != m_group_to_items.end();) {
|
||||||
iter_groups != m_group_to_items.end();) {
|
|
||||||
GroupItems &items = iter_groups->second;
|
GroupItems &items = iter_groups->second;
|
||||||
for (GroupItems::iterator iter_groupitems = items.begin();
|
for (GroupItems::iterator iter_groupitems = items.begin();
|
||||||
iter_groupitems != items.end();) {
|
iter_groupitems != items.end();) {
|
||||||
if (iter_groupitems->first == id)
|
if (iter_groupitems->first == id)
|
||||||
items.erase(iter_groupitems++);
|
items.erase(iter_groupitems++);
|
||||||
else
|
else
|
||||||
iter_groupitems++;
|
++iter_groupitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if group is empty
|
// Check if group is empty
|
||||||
if (items.size() == 0)
|
if (items.size() == 0)
|
||||||
m_group_to_items.erase(iter_groups++);
|
m_group_to_items.erase(iter_groups++);
|
||||||
else
|
else
|
||||||
iter_groups++;
|
++iter_groups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,26 +46,26 @@ AsyncEngine::~AsyncEngine()
|
|||||||
|
|
||||||
// Request all threads to stop
|
// Request all threads to stop
|
||||||
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
||||||
it != workerThreads.end(); it++) {
|
it != workerThreads.end(); ++it) {
|
||||||
(*it)->stop();
|
(*it)->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Wake up all threads
|
// Wake up all threads
|
||||||
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
||||||
it != workerThreads.end(); it++) {
|
it != workerThreads.end(); ++it) {
|
||||||
jobQueueCounter.post();
|
jobQueueCounter.post();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for threads to finish
|
// Wait for threads to finish
|
||||||
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
||||||
it != workerThreads.end(); it++) {
|
it != workerThreads.end(); ++it) {
|
||||||
(*it)->wait();
|
(*it)->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force kill all threads
|
// Force kill all threads
|
||||||
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
|
||||||
it != workerThreads.end(); it++) {
|
it != workerThreads.end(); ++it) {
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) {
|
|||||||
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
|
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
|
||||||
{
|
{
|
||||||
for (UNORDERED_MAP<std::string, lua_CFunction>::iterator it = functionList.begin();
|
for (UNORDERED_MAP<std::string, lua_CFunction>::iterator it = functionList.begin();
|
||||||
it != functionList.end(); it++) {
|
it != functionList.end(); ++it) {
|
||||||
lua_pushstring(L, it->first.c_str());
|
lua_pushstring(L, it->first.c_str());
|
||||||
lua_pushcfunction(L, it->second);
|
lua_pushcfunction(L, it->second);
|
||||||
lua_settable(L, top);
|
lua_settable(L, top);
|
||||||
|
@ -263,7 +263,7 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
|
|||||||
lua_pushstring(L, formname.c_str()); // formname
|
lua_pushstring(L, formname.c_str()); // formname
|
||||||
lua_newtable(L); // fields
|
lua_newtable(L); // fields
|
||||||
StringMap::const_iterator it;
|
StringMap::const_iterator it;
|
||||||
for (it = fields.begin(); it != fields.end(); it++) {
|
for (it = fields.begin(); it != fields.end(); ++it) {
|
||||||
const std::string &name = it->first;
|
const std::string &name = it->first;
|
||||||
const std::string &value = it->second;
|
const std::string &value = it->second;
|
||||||
lua_pushstring(L, name.c_str());
|
lua_pushstring(L, name.c_str());
|
||||||
|
@ -83,7 +83,7 @@ int ModApiClient::l_get_player_names(lua_State *L)
|
|||||||
int newTable = lua_gettop(L);
|
int newTable = lua_gettop(L);
|
||||||
int index = 1;
|
int index = 1;
|
||||||
std::list<std::string>::const_iterator iter;
|
std::list<std::string>::const_iterator iter;
|
||||||
for (iter = plist.begin(); iter != plist.end(); iter++) {
|
for (iter = plist.begin(); iter != plist.end(); ++iter) {
|
||||||
lua_pushstring(L, (*iter).c_str());
|
lua_pushstring(L, (*iter).c_str());
|
||||||
lua_rawseti(L, newTable, index);
|
lua_rawseti(L, newTable, index);
|
||||||
index++;
|
index++;
|
||||||
|
@ -414,7 +414,7 @@ static void push_craft_recipe(lua_State *L, IGameDef *gdef,
|
|||||||
|
|
||||||
lua_newtable(L); // items
|
lua_newtable(L); // items
|
||||||
std::vector<ItemStack>::const_iterator iter = input.items.begin();
|
std::vector<ItemStack>::const_iterator iter = input.items.begin();
|
||||||
for (u16 j = 1; iter != input.items.end(); iter++, j++) {
|
for (u16 j = 1; iter != input.items.end(); ++iter, j++) {
|
||||||
if (iter->empty())
|
if (iter->empty())
|
||||||
continue;
|
continue;
|
||||||
lua_pushstring(L, iter->name.c_str());
|
lua_pushstring(L, iter->name.c_str());
|
||||||
|
@ -534,7 +534,7 @@ int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
|
|||||||
ScriptApiBase *script = getScriptApiBase(L);
|
ScriptApiBase *script = getScriptApiBase(L);
|
||||||
lua_createtable(L, ids.size(), 0);
|
lua_createtable(L, ids.size(), 0);
|
||||||
std::vector<u16>::const_iterator iter = ids.begin();
|
std::vector<u16>::const_iterator iter = ids.begin();
|
||||||
for(u32 i = 0; iter != ids.end(); iter++) {
|
for(u32 i = 0; iter != ids.end(); ++iter) {
|
||||||
ServerActiveObject *obj = env->getActiveObject(*iter);
|
ServerActiveObject *obj = env->getActiveObject(*iter);
|
||||||
// Insert object reference into table
|
// Insert object reference into table
|
||||||
script->objectrefGetOrCreate(L, obj);
|
script->objectrefGetOrCreate(L, obj);
|
||||||
@ -985,8 +985,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
|
|||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
unsigned int index = 1;
|
unsigned int index = 1;
|
||||||
for (std::vector<v3s16>::iterator i = path.begin(); i != path.end();i++)
|
for (std::vector<v3s16>::iterator i = path.begin(); i != path.end(); ++i) {
|
||||||
{
|
|
||||||
lua_pushnumber(L,index);
|
lua_pushnumber(L,index);
|
||||||
push_v3s16(L, *i);
|
push_v3s16(L, *i);
|
||||||
lua_settable(L, top);
|
lua_settable(L, top);
|
||||||
|
@ -297,7 +297,7 @@ int ModApiMainMenu::l_get_games(lua_State *L)
|
|||||||
int table2 = lua_gettop(L);
|
int table2 = lua_gettop(L);
|
||||||
int internal_index=1;
|
int internal_index=1;
|
||||||
for (std::set<std::string>::iterator iter = games[i].addon_mods_paths.begin();
|
for (std::set<std::string>::iterator iter = games[i].addon_mods_paths.begin();
|
||||||
iter != games[i].addon_mods_paths.end(); iter++) {
|
iter != games[i].addon_mods_paths.end(); ++iter) {
|
||||||
lua_pushnumber(L,internal_index);
|
lua_pushnumber(L,internal_index);
|
||||||
lua_pushstring(L,(*iter).c_str());
|
lua_pushstring(L,(*iter).c_str());
|
||||||
lua_settable(L, table2);
|
lua_settable(L, table2);
|
||||||
|
@ -107,7 +107,7 @@ void NodeMetaRef::handleToTable(lua_State *L, Metadata *_meta)
|
|||||||
if (inv) {
|
if (inv) {
|
||||||
std::vector<const InventoryList *> lists = inv->getLists();
|
std::vector<const InventoryList *> lists = inv->getLists();
|
||||||
for(std::vector<const InventoryList *>::const_iterator
|
for(std::vector<const InventoryList *>::const_iterator
|
||||||
i = lists.begin(); i != lists.end(); i++) {
|
i = lists.begin(); i != lists.end(); ++i) {
|
||||||
push_inventory_list(L, inv, (*i)->getName().c_str());
|
push_inventory_list(L, inv, (*i)->getName().c_str());
|
||||||
lua_setfield(L, -2, (*i)->getName().c_str());
|
lua_setfield(L, -2, (*i)->getName().c_str());
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ int ModApiServer::l_get_player_privs(lua_State *L)
|
|||||||
int table = lua_gettop(L);
|
int table = lua_gettop(L);
|
||||||
std::set<std::string> privs_s = server->getPlayerEffectivePrivs(name);
|
std::set<std::string> privs_s = server->getPlayerEffectivePrivs(name);
|
||||||
for(std::set<std::string>::const_iterator
|
for(std::set<std::string>::const_iterator
|
||||||
i = privs_s.begin(); i != privs_s.end(); i++){
|
i = privs_s.begin(); i != privs_s.end(); ++i){
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
lua_setfield(L, table, i->c_str());
|
lua_setfield(L, table, i->c_str());
|
||||||
}
|
}
|
||||||
@ -417,7 +417,7 @@ int ModApiServer::l_get_modnames(lua_State *L)
|
|||||||
// Package them up for Lua
|
// Package them up for Lua
|
||||||
lua_createtable(L, modlist.size(), 0);
|
lua_createtable(L, modlist.size(), 0);
|
||||||
std::vector<std::string>::iterator iter = modlist.begin();
|
std::vector<std::string>::iterator iter = modlist.begin();
|
||||||
for (u16 i = 0; iter != modlist.end(); iter++) {
|
for (u16 i = 0; iter != modlist.end(); ++iter) {
|
||||||
lua_pushstring(L, iter->c_str());
|
lua_pushstring(L, iter->c_str());
|
||||||
lua_rawseti(L, -2, ++i);
|
lua_rawseti(L, -2, ++i);
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,8 @@ public:
|
|||||||
GetRequest() {}
|
GetRequest() {}
|
||||||
~GetRequest() {}
|
~GetRequest() {}
|
||||||
|
|
||||||
GetRequest(Key a_key) {
|
GetRequest(const Key &a_key): key(a_key)
|
||||||
key = a_key;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
@ -106,7 +106,7 @@ public:
|
|||||||
return m_queue.empty();
|
return m_queue.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(Key key, Caller caller, CallerData callerdata,
|
void add(const Key &key, Caller caller, CallerData callerdata,
|
||||||
ResultQueue<Key, T, Caller, CallerData> *dest)
|
ResultQueue<Key, T, Caller, CallerData> *dest)
|
||||||
{
|
{
|
||||||
typename std::deque<GetRequest<Key, T, Caller, CallerData> >::iterator i;
|
typename std::deque<GetRequest<Key, T, Caller, CallerData> >::iterator i;
|
||||||
|
Loading…
Reference in New Issue
Block a user