From 7528986e4449febead9b18b6118f0b096f7cf800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Sat, 19 Aug 2017 14:25:35 +0200 Subject: Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) * Code modernization: src/p*, src/q*, src/r*, src/s* (partial) * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Spelling: vertice -> vertex --- src/server.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index c74cc5394..f48066fad 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -359,10 +359,8 @@ Server::~Server() delete m_script; // Delete detached inventories - for (std::map::iterator - i = m_detached_inventories.begin(); - i != m_detached_inventories.end(); ++i) { - delete i->second; + for (auto &detached_inventory : m_detached_inventories) { + delete detached_inventory.second; } } @@ -2298,14 +2296,12 @@ void Server::fillMediaCache() paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server"); // Collect media file information from paths into cache - for(std::vector::iterator i = paths.begin(); - i != paths.end(); ++i) { - std::string mediapath = *i; + for (const std::string &mediapath : paths) { std::vector dirlist = fs::GetDirListing(mediapath); - for (u32 j = 0; j < dirlist.size(); j++) { - if (dirlist[j].dir) // Ignode dirs + for (const fs::DirListNode &dln : dirlist) { + if (dln.dir) // Ignode dirs continue; - std::string filename = dirlist[j].name; + std::string filename = dln.name; // If name contains illegal characters, ignore the file if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) { infostream<<"Server: ignoring illegal file name: \"" @@ -2326,7 +2322,9 @@ void Server::fillMediaCache() continue; } // Ok, attempt to load the file and add to cache - std::string filepath = mediapath + DIR_DELIM + filename; + std::string filepath; + filepath.append(mediapath).append(DIR_DELIM).append(filename); + // Read data std::ifstream fis(filepath.c_str(), std::ios_base::binary); if (!fis.good()) { -- cgit v1.2.3