[Boost-bugs] [Boost C++ Libraries] #9480: make_permissions slower then it needs to me

Subject: [Boost-bugs] [Boost C++ Libraries] #9480: make_permissions slower then it needs to me
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-12-09 13:06:56


#9480: make_permissions slower then it needs to me
-----------------------------------------+--------------------------
 Reporter: Adrian Dorr <a.dorr@…> | Owner: bemandawes
     Type: Patches | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost Development Trunk | Severity: Optimization
 Keywords: filesystem make_permissions |
-----------------------------------------+--------------------------
 in libs\filesystem\src\operations.cpp the make_permissions calls
 path::extension four times, which accounts for pretty much 100% of the cpu
 cycles outside the OS call of the directory iterators increment function.
 A better approach would be to get the extension string once and reuse it
 four times. Even better would be to find the last '.' in the filename and
 avoid the extra std::string construction.

   perms make_permissions(const path& p, DWORD attr)
   {
     perms prms = fs::owner_read | fs::group_read | fs::others_read;
     if ((attr & FILE_ATTRIBUTE_READONLY) == 0)
       prms |= fs::owner_write | fs::group_write | fs::others_write;
     std::string ext = p.extension().string();
     if (BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".exe") == 0
       || BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".com") == 0
       || BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".bat") == 0
       || BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".cmd") == 0)
       prms |= fs::owner_exe | fs::group_exe | fs::others_exe;
     return prms;
   }

 Or for extra performance (avoids construction of one std::string for the
 extension at the price of extra nasty code):

   perms make_permissions(const path& p, DWORD attr)
   {
     perms prms = fs::owner_read | fs::group_read | fs::others_read;
     if ((attr & FILE_ATTRIBUTE_READONLY) == 0)
       prms |= fs::owner_write | fs::group_write | fs::others_write;
     const std::string& path_str = p.string();
     if (path_str.size() >= 4) {
       const char* ext = path_str.c_str() + path_str.size() - 4;
       if (BOOST_FILESYSTEM_STRICMP(ext, ".exe") == 0
         || BOOST_FILESYSTEM_STRICMP(ext, ".com") == 0
         || BOOST_FILESYSTEM_STRICMP(ext, ".bat") == 0
         || BOOST_FILESYSTEM_STRICMP(ext, ".cmd") == 0)
         prms |= fs::owner_exe | fs::group_exe | fs::others_exe;
     }
     return prms;
   }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9480>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC