Anonymous | Login | Signup for a new account | 2024-04-25 15:45 UTC |
My View | View Issues | Change Log | Roadmap | Doomseeker Issue Support Ranking | Rules | My Account |
View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||||||
0003814 | Doomseeker | [All Projects] Cleanup | public | 2020-06-07 05:20 | 2020-06-07 20:41 | ||||||||
Reporter | WubTheCaptain | ||||||||||||
Assigned To | |||||||||||||
Priority | none | Severity | minor | Reproducibility | sometimes | ||||||||
Status | confirmed | Resolution | open | ||||||||||
Platform | OS | OS Version | |||||||||||
Product Version | 1.3.1 | ||||||||||||
Target Version | Fixed in Version | ||||||||||||
Summary | 0003814: Inefficient string concatenation | ||||||||||||
Description | operator+ creates temporary strings and unnecessary copies. std::string’s (std::basic_string) class member function append(), and QString::appendmember, calculate the final result without any temporaries. Affects performance. | ||||||||||||
Steps To Reproduce | Here's an example:Quote from src/core/irc/ircnetworkadapter.cppvoid IRCNetworkAdapter::setChannelMode(const QString &channel, const QString &nickname, const QString &flag, bool bSet) { /* ... */ QString flagPrefixed; if (bSet) flagPrefixed = "+" + flag.trimmed(); else flagPrefixed = "-" + flag.trimmed(); /* ... */ } There are many more. They're not always easy to search for. $ grep -r '" + "' src/ | wc -l 1 $ grep -r '" + ' src/ | wc -l 98 $ grep -r ' + "' src/ | wc -l 118 Assumed good behavior: $ grep -r "\.append(" src/ | wc -l 72 | ||||||||||||
Additional Information | 'https://clang.llvm.org/extra/clang-tidy/checks/performance-inefficient-string-concatenation.html [^]' 'https://www.qt.io/blog/efficient-qstring-concatenation-with-c17-fold-expressions [^]' | ||||||||||||
Attached Files | |||||||||||||
Notes | |
(0021366) WubTheCaptain (reporter) 2020-06-07 05:23 |
Actually, that might be a terrible example in OP's steps to reproduce. Is it? |
(0021388) Pol M (developer) 2020-06-07 20:41 |
Sounds good to me :)Quote from Wub This particular case is not inefficient as the constructed string will simply get assigned to the flagPrefixed (and the default constructed one will get destroyed), but I'm sure we have a few of these out there. |
Only registered users can voice their support. Click here to register, or here to log in. | |
Supporters: | No one explicitly supports this issue yet. |
Opponents: | No one explicitly opposes this issue yet. |
Issue History | |||
Date Modified | Username | Field | Change |
2020-06-07 05:20 | WubTheCaptain | New Issue | |
2020-06-07 05:20 | WubTheCaptain | Steps to Reproduce Updated | View Revisions |
2020-06-07 05:20 | WubTheCaptain | Steps to Reproduce Updated | View Revisions |
2020-06-07 05:23 | WubTheCaptain | Note Added: 0021366 | |
2020-06-07 20:41 | Pol M | Note Added: 0021388 | |
2020-06-07 20:41 | Pol M | Status | new => confirmed |
Copyright © 2000 - 2024 MantisBT Team |