Skip to content
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

Optimized tooltip generation in WBaseWidget #13952

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JoergAtGithub
Copy link
Member

Code cleanup. Main change is that empty lines at the end of the tooltips are no longer printed.

}
m_pWidget->setToolTip(debug.join("\n"));
m_pWidget->setToolTip(debug.join(QStringLiteral("\n")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_pWidget->setToolTip(debug.join(QStringLiteral("\n")));
m_pWidget->setToolTip(debug.join(QChar('\n')));

}
for (const auto& pControlConnection : std::as_const(m_connections)) {
*debug << QString("Connection: %1").arg(pControlConnection->toDebugString());
*debug << QStringLiteral("ClassName: %1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is supposed to be an optimization, you may want to consider reserving space as appropriate. This adds quite a lot of elements, so it needs to reallocate at least once, avoiding the second allocation by reserving enough upfront may make sense.

Suggested change
*debug << QStringLiteral("ClassName: %1")
debug->reserve(debug.size() + 7 + m_leftConnections.size() + m_rightConnections.size() + m_connections.size() + 1);
*debug << QStringLiteral("ClassName: %1")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The QStringBuilder does it implicit for us, if we replace the %1 placeholder by normal string concat using +.
However is it worth the efforts in this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug is a QList<QString>. I don't see how QStringBuilder is relevant here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean
QStringLiteral("ObjectName: %1").arg(m_pWidget->objectName())
->
QStringLiteral("ObjectName: ") + m_pWidget->objectName()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that makes a meaningful difference for a single argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants