1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-18 00:59:43 +02:00

Convert file name to C++ string as late as possible

This avoids copying the string if the file is rejected because its
category (directory or regular file) is disabled.
This commit is contained in:
Maarten ter Huurne 2014-08-14 05:30:31 +02:00
parent b6f6bb387c
commit 56beec0895

View File

@ -93,7 +93,6 @@ void FileLister::browse(const string& path, bool clean)
} }
} }
string file = dptr->d_name;
bool isDir; bool isDir;
#ifdef DT_DIR #ifdef DT_DIR
if (dptr->d_type != DT_UNKNOWN) { if (dptr->d_type != DT_UNKNOWN) {
@ -101,7 +100,7 @@ void FileLister::browse(const string& path, bool clean)
} else } else
#endif #endif
{ {
string filepath = slashedPath + file; string filepath = slashedPath + dptr->d_name;
struct stat st; struct stat st;
int statRet = stat(filepath.c_str(), &st); int statRet = stat(filepath.c_str(), &st);
if (statRet == -1) { if (statRet == -1) {
@ -115,16 +114,17 @@ void FileLister::browse(const string& path, bool clean)
if (!showDirectories) if (!showDirectories)
continue; continue;
directorySet.insert(file); directorySet.insert(string(dptr->d_name));
} else { } else {
if (!showFiles) if (!showFiles)
continue; continue;
if (filter.empty()) { if (filter.empty()) {
fileSet.insert(file); fileSet.insert(string(dptr->d_name));
continue; continue;
} }
string file = dptr->d_name;
for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) { for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) {
if (file.find('.') == string::npos) { if (file.find('.') == string::npos) {
if (!it->empty()) if (!it->empty())