Boost C++ Libraries: Ticket #9480: make_permissions slower then it needs to be https://svn.boost.org/trac10/ticket/9480 <p> 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. </p> <blockquote> <p> perms make_permissions(const path&amp; p, DWORD attr) { </p> <blockquote> <p> perms prms = fs::owner_read | fs::group_read | fs::others_read; if ((attr &amp; FILE_ATTRIBUTE_READONLY) == 0) </p> <blockquote> <p> prms |= fs::owner_write | fs::group_write | fs::others_write; </p> </blockquote> <p> std::string ext = p.extension().string(); if (BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".exe") == 0 </p> <blockquote> <table class="wiki"> <tr><td> BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".com") == 0 </td></tr><tr><td> BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".bat") == 0 </td></tr><tr><td> BOOST_FILESYSTEM_STRICMP(ext.c_str(), ".cmd") == 0) </td></tr></table> <p> prms |= fs::owner_exe | fs::group_exe | fs::others_exe; </p> </blockquote> <p> return prms; </p> </blockquote> <p> } </p> </blockquote> <p> Or for extra performance (avoids construction of one std::string for the extension at the price of extra nasty code): </p> <blockquote> <p> perms make_permissions(const path&amp; p, DWORD attr) { </p> <blockquote> <p> perms prms = fs::owner_read | fs::group_read | fs::others_read; if ((attr &amp; FILE_ATTRIBUTE_READONLY) == 0) </p> <blockquote> <p> prms |= fs::owner_write | fs::group_write | fs::others_write; </p> </blockquote> <p> const std::string&amp; path_str = p.string(); if (path_str.size() &gt;= 4) { </p> <blockquote> <p> const char* ext = path_str.c_str() + path_str.size() - 4; if (BOOST_FILESYSTEM_STRICMP(ext, ".exe") == 0 </p> <blockquote> <table class="wiki"> <tr><td> BOOST_FILESYSTEM_STRICMP(ext, ".com") == 0 </td></tr><tr><td> BOOST_FILESYSTEM_STRICMP(ext, ".bat") == 0 </td></tr><tr><td> BOOST_FILESYSTEM_STRICMP(ext, ".cmd") == 0) </td></tr></table> <p> prms |= fs::owner_exe | fs::group_exe | fs::others_exe; </p> </blockquote> </blockquote> <p> } return prms; </p> </blockquote> <p> } </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9480 Trac 1.4.3 Adrian Dorr <a.dorr@…> Mon, 09 Dec 2013 13:07:45 GMT summary changed https://svn.boost.org/trac10/ticket/9480#comment:1 https://svn.boost.org/trac10/ticket/9480#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">make_permissions slower then it needs to me</span> → <span class="trac-field-new">make_permissions slower then it needs to be</span> </li> </ul> Ticket Daniel Krügler <daniel.kruegler@…> Fri, 31 Oct 2014 23:12:33 GMT <link>https://svn.boost.org/trac10/ticket/9480#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9480#comment:2</guid> <description> <p> Ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/10731" title="#10731: Bugs: make_permissions is case-inconsistent and requires unnecessary conversions (new)">#10731</a> suggests some further improvements </p> </description> <category>Ticket</category> </item> <item> <author>daniel.kruegler@…</author> <pubDate>Tue, 14 Mar 2017 20:53:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9480#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9480#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9480#comment:2" title="Comment 2">Daniel Krügler &lt;daniel.kruegler@…&gt;</a>: </p> <blockquote class="citation"> <p> Ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/10731" title="#10731: Bugs: make_permissions is case-inconsistent and requires unnecessary conversions (new)">#10731</a> suggests some further improvements </p> </blockquote> <p> Based on that patch suggestion in ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/10731" title="#10731: Bugs: make_permissions is case-inconsistent and requires unnecessary conversions (new)">#10731</a> I have created a pull request via the github project: </p> <p> <a class="ext-link" href="https://github.com/boostorg/filesystem/pull/41/commits/755766a0536df599ac0280428defad03dac92cfc"><span class="icon">​</span>https://github.com/boostorg/filesystem/pull/41/commits/755766a0536df599ac0280428defad03dac92cfc</a> </p> <p> Please consider this request, it also solves the code conversion problem described in ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/10731" title="#10731: Bugs: make_permissions is case-inconsistent and requires unnecessary conversions (new)">#10731</a>. </p> </description> <category>Ticket</category> </item> <item> <author>daniel.kruegler@…</author> <pubDate>Sun, 30 Apr 2017 17:17:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9480#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9480#comment:4</guid> <description> <p> This issue should be marked as resolved by accepting the pull request </p> <p> <a class="ext-link" href="https://github.com/boostorg/filesystem/commit/0e831d5c2d9c5a7baed75cfe2fb914daaf4a6182"><span class="icon">​</span>https://github.com/boostorg/filesystem/commit/0e831d5c2d9c5a7baed75cfe2fb914daaf4a6182</a> </p> <p> for Boost version 1.64. </p> </description> <category>Ticket</category> </item> </channel> </rss>