Opened 9 years ago

Last modified 5 years ago

#9480 new Patches

make_permissions slower then it needs to be

Reported by: Adrian Dorr <a.dorr@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost Development Trunk Severity: Optimization
Keywords: filesystem make_permissions Cc: a.dorr@…

Description

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;

}

Change History (4)

comment:1 by Adrian Dorr <a.dorr@…>, 9 years ago

Summary: make_permissions slower then it needs to memake_permissions slower then it needs to be

comment:2 by Daniel Krügler <daniel.kruegler@…>, 8 years ago

Ticket #10731 suggests some further improvements

in reply to:  2 comment:3 by daniel.kruegler@…, 6 years ago

Replying to Daniel Krügler <daniel.kruegler@…>:

Ticket #10731 suggests some further improvements

Based on that patch suggestion in ticket #10731 I have created a pull request via the github project:

https://github.com/boostorg/filesystem/pull/41/commits/755766a0536df599ac0280428defad03dac92cfc

Please consider this request, it also solves the code conversion problem described in ticket #10731.

comment:4 by daniel.kruegler@…, 5 years ago

This issue should be marked as resolved by accepting the pull request

https://github.com/boostorg/filesystem/commit/0e831d5c2d9c5a7baed75cfe2fb914daaf4a6182

for Boost version 1.64.

Note: See TracTickets for help on using tickets.