From 56beec089539c55d4a60d1eabe98aacc9ca3b3d7 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Thu, 14 Aug 2014 05:30:31 +0200 Subject: [PATCH] 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. --- src/filelister.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/filelister.cpp b/src/filelister.cpp index 9269033..a0bc106 100644 --- a/src/filelister.cpp +++ b/src/filelister.cpp @@ -93,7 +93,6 @@ void FileLister::browse(const string& path, bool clean) } } - string file = dptr->d_name; bool isDir; #ifdef DT_DIR if (dptr->d_type != DT_UNKNOWN) { @@ -101,7 +100,7 @@ void FileLister::browse(const string& path, bool clean) } else #endif { - string filepath = slashedPath + file; + string filepath = slashedPath + dptr->d_name; struct stat st; int statRet = stat(filepath.c_str(), &st); if (statRet == -1) { @@ -115,16 +114,17 @@ void FileLister::browse(const string& path, bool clean) if (!showDirectories) continue; - directorySet.insert(file); + directorySet.insert(string(dptr->d_name)); } else { if (!showFiles) continue; if (filter.empty()) { - fileSet.insert(file); + fileSet.insert(string(dptr->d_name)); continue; } + string file = dptr->d_name; for (vector::iterator it = filter.begin(); it != filter.end(); ++it) { if (file.find('.') == string::npos) { if (!it->empty())