-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qt: Optimize string concatenation by default #313
Conversation
daa63ed
to
b4e1480
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
@@ -114,7 +114,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const | |||
return (qint64)rec->nodeStats.nodeid; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is motive for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK a02c970, built successfully on Debian Sid with Qt 5.15.2, but did not check if any displayed strings are "wrong" after refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a02c970
Tested most of the strings on Qt 5.15.2 macOS 11.3
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.include
file does not justify submitting this PR into the main repo, IMHO.