From b202f1949aa0b47b8652f973f3d1abdfee2b2c98 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 15 Aug 2014 14:27:05 +0200 Subject: [PATCH] Minor optimizations in Menu Use emplace_back when a new string is put into a vector. Removed unused variables. When searching section names, compare C++ string to C string, so we don't need to construct a C++ string for the second string just for the search. --- src/menu.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index b8a2a6a..6e43b8c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -120,10 +120,8 @@ void Menu::readSections(std::string parentDir) if (dptr->d_name[0] == '.' || dptr->d_type != DT_DIR) continue; - string filepath = parentDir + "/" + dptr->d_name; - - if (find(sections.begin(), sections.end(), (string)dptr->d_name) == sections.end()) { - sections.push_back((string)dptr->d_name); + if (find(sections.begin(), sections.end(), dptr->d_name) == sections.end()) { + sections.emplace_back(dptr->d_name); vector ll; links.push_back(ll); } @@ -802,8 +800,7 @@ void Menu::readLinksOfSection(std::string path, std::vector &linkfi while ((dptr = readdir(dirp))) { if (dptr->d_type != DT_REG) continue; - string filepath = path + "/" + dptr->d_name; - linkfiles.push_back(filepath); + linkfiles.emplace_back(path + "/" + dptr->d_name); } closedir(dirp); @@ -836,7 +833,6 @@ void Menu::readLinks() { iLink = 0; iFirstDispRow = 0; - string filepath; for (uint i=0; i