qt: Optimize string concatenation by default#313
Conversation
daa63ed to
b4e1480
Compare
jarolrod
left a comment
There was a problem hiding this comment.
ACK b4e1480 🥃
This simplifies and reduces the mental burden of having to think about "am I concatenating a string in the most efficient way possible?"
I could not find any other occurrences of including QStringBuilder or occurrences of concatenating string with %.
|
Could you look into this PR? |
|
It's true that QtCreator, and Qt itself is built with that flag, but we might want to discuss if we want that "implicit magic". There is some caveat with this kind of code: "maybe" it is possible to write similar code and "sometimes" not crash, IDK. Not sure if this is dangerous in any new code, i.e. if it will be missed by reviewers, if it will pass without "sometimes" crashing, etc. Although, we are talking about GUI code, so.. not sure. I personally still use |
| case Address: | ||
| // prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection | ||
| return QString(rec->nodeStats.fInbound ? "↓ " : "↑ ") + QString::fromStdString(rec->nodeStats.addrName); | ||
| return QString::fromStdString((rec->nodeStats.fInbound ? "↓ " : "↑ ") + rec->nodeStats.addrName); |
There was a problem hiding this comment.
qt/peertablemodel.cpp:117:20: error: no viable conversion from returned value of type 'QStringBuilder<typename QConcatenable<QString>::type, typename QConcatenable<QString>::type>' (aka 'QStringBuilder<QString, QString>') to function return type 'QVariant'
return QString(rec->nodeStats.fInbound ? "↓ " : "↑ ") + QString::fromStdString(rec->nodeStats.addrName);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You are right! Discussion is a good mean to reach (rough) consensus about suggested changes.
You code snippet could be fixed by s/ |
The defined QT_USE_QSTRINGBUILDER macro means using the QStringBuilder for efficient string concatenation in all Qt code by default.
Yes, but that's the "danger", as one needs to know these kinda caveats. Yes, docs could help. |
|
Code review ACK a02c970
I don't think there is any place in bitcoin where concatenating Qt strings is actually a bottleneck, but agree with this perspective.
That's reassuring also in the sense that it probably won't just go away. |
|
Approach ACK, this looks like a good idea indeed. |
From Qt docs:
With this PR
The change in the
src/Makefile.qt.includefile does not justify submitting this PR into the main repo, IMHO.