Zandronum Chat @ irc.zandronum.com
#zandronum
Get the latest version: 3.0
Source Code

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003814Doomseeker[All Projects] Cleanuppublic2020-06-07 05:202020-06-07 20:41
ReporterWubTheCaptain 
Assigned To 
PrioritynoneSeverityminorReproducibilitysometimes
StatusconfirmedResolutionopen 
PlatformOSOS Version
Product Version1.3.1 
Target VersionFixed in Version 
Summary0003814: Inefficient string concatenation
Descriptionoperator+ 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 ReproduceHere's an example:
Quote from src/core/irc/ircnetworkadapter.cpp
void 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 Informationhttps://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

- Relationships

-  Notes
User avatar (0021366)
WubTheCaptain (developer)
2020-06-07 05:23

Actually, that might be a terrible example in OP's steps to reproduce. Is it?
User avatar (0021388)
Pol M (developer)
2020-06-07 20:41

Sounds good to me :)
Quote from Wub

Actually, that might be a terrible example in OP's steps to reproduce. Is it?

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.

Issue Community Support
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






Questions or other issues? Contact Us.

Links


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker