Commit 523f74ab authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Use reserve to minimize temporary allocations

parent c95c9f12
......@@ -171,6 +171,7 @@ public:
// collect rects for each word
QVector<QPair<QRect, QString>> btns;
const auto list = shortcutString.split(QLatin1Char('+'));
btns.reserve(list.size());
for (const QString& text : list) {
QRect r = option.fontMetrics.boundingRect(text);
r.setWidth(r.width() + 8);
......@@ -274,16 +275,19 @@ KateCommandBar::KateCommandBar(QWidget *parent)
setHidden(true);
}
void KateCommandBar::updateBar(const QList<KActionCollection *> &actionCollections)
void KateCommandBar::updateBar(const QList<KActionCollection *> &actionCollections, int totalActions)
{
QVector<QPair<QString, QAction*>> actionList;
actionList.reserve(totalActions);
for (const auto collection : actionCollections) {
const QList<QAction*> collectionActions = collection->actions();
const QString componentName = collection->componentDisplayName();
for (const auto action : collectionActions) {
// sanity + empty check ensures displayable actions and removes ourself
// from the action list
if (action && !action->text().isEmpty()) {
actionList.append({collection->componentDisplayName(), action});
actionList.append({componentName, action});
}
}
}
......@@ -352,7 +356,7 @@ void KateCommandBar::slotReturnPressed()
menuActions = menu->actions();
}
for (auto menuAction : menuActions) {
for (auto menuAction : qAsConst(menuActions)) {
if (menuAction) {
list.append({KLocalizedString::removeAcceleratorMarker(act->text()), menuAction});
}
......
......@@ -19,7 +19,7 @@ class KateCommandBar : public QMenu
public:
KateCommandBar(QWidget* parent = nullptr);
void updateBar(const QList<KActionCollection*>& actions);
void updateBar(const QList<KActionCollection*>& actions, int totalActions);
void updateViewGeometry();
......
......@@ -1221,17 +1221,18 @@ void KateMainWindow::slotCommandBarOpen()
QList<KActionCollection*> actionCollections;
auto clients = guiFactory()->clients();
int actionsCount = 0;
for (const KXMLGUIClient* c : clients) {
if (!c) {
continue;
}
if (!c->actionCollection()) {
continue;
if (auto collection = c->actionCollection()) {
actionCollections.append(collection);
actionsCount += collection->count();
}
actionCollections.append(c->actionCollection());
}
m_commandBar->updateBar(actionCollections);
m_commandBar->updateBar(actionCollections, actionsCount);
centralWidget()->setFocusProxy(m_commandBar);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment