From 5bc3fe52f7b5803cb331fba1a301c97776d16a5d Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Mon, 13 Jun 2016 14:03:05 +0900 Subject: [PATCH] Don't allocate/construct additional std::string file visitor is one of the most frequently running part of program so it needed to being downsized is highly recommended Change-Id: Ib317b9420329b1ad25b4db6310d3cce53b39f95f Signed-off-by: Kyungwook Tak --- src/framework/service/file-system.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp index 6e3c94e..8b29beb 100644 --- a/src/framework/service/file-system.cpp +++ b/src/framework/service/file-system.cpp @@ -93,11 +93,7 @@ bool File::isInApp(const std::string &path) else continue; - auto types = File::getPkgTypes(pkgId); - if (types & static_cast(Type::Package)) - return true; - else - break; + return File::getPkgTypes(pkgId) != 0; } return false; @@ -124,11 +120,7 @@ std::string File::getPkgPath(const std::string &path) continue; } - auto types = File::getPkgTypes(pkgId); - if (types & static_cast(Type::Package)) - return pkgPath; - else - break; + return File::getPkgTypes(pkgId) != 0 ? pkgPath : path; } return path; @@ -304,31 +296,38 @@ FilePtr FsVisitor::next() } auto &dir = this->m_dirs.front(); - std::string filepath(result->d_name); + const auto &name = result->d_name; + auto name_size = ::strlen(name); + + if (name_size == 0) + continue; if (result->d_type == DT_DIR) { - if (filepath.compare(".") != 0 && filepath.compare("..") != 0) - this->m_dirs.emplace( - dir + ((filepath.back() == '/') ? filepath : (filepath + '/'))); + if (name_size == 1 && ::strcmp(name, ".") == 0) + continue; + else if (name_size == 2 && ::strcmp(name, "..") == 0) + continue; + + this->m_dirs.emplace(dir + name + '/'); } else if (result->d_type == DT_REG) { try { - auto fileptr = File::createIfModified(dir + filepath, this->m_since); + auto fileptr = File::createIfModified(dir + name, this->m_since); if (fileptr) return fileptr; } catch (const Exception &e) { if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST) - WARN("file not exist: " << dir << filepath << " msg: " << e.what()); + WARN("file not exist: " << dir << name << " msg: " << e.what()); else if (e.error() == CSR_ERROR_FILE_SYSTEM) WARN("file type is not regular...? can it be happened?" - " :" << dir << filepath << " msg: " << e.what()); + " :" << dir << name << " msg: " << e.what()); else throw; } } } - ThrowExc(CSR_ERROR_FILE_SYSTEM, "readdir_r error on dir: " << this->m_dirs.front()); + return nullptr; } } // namespace Csr -- 2.7.4