summaryrefslogtreecommitdiff
path: root/src/protocols/GlobalShortcuts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols/GlobalShortcuts.cpp')
-rw-r--r--src/protocols/GlobalShortcuts.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/protocols/GlobalShortcuts.cpp b/src/protocols/GlobalShortcuts.cpp
index 6fac2d7f..9f8f422c 100644
--- a/src/protocols/GlobalShortcuts.cpp
+++ b/src/protocols/GlobalShortcuts.cpp
@@ -83,8 +83,19 @@ void CGlobalShortcutsProtocol::sendGlobalShortcutEvent(std::string appid, std::s
std::vector<SShortcut> CGlobalShortcutsProtocol::getAllShortcuts() {
std::vector<SShortcut> copy;
- for (auto const& c : m_vClients) {
- for (auto const& sh : c->shortcuts) {
+ // calculate the total number of shortcuts, precomputing size is linear
+ // and potential reallocation is more costly then the added precompute overhead of looping
+ // and finding the total size.
+ size_t totalShortcuts = 0;
+ for (const auto& c : m_vClients) {
+ totalShortcuts += c->shortcuts.size();
+ }
+
+ // reserve number of elements to avoid reallocations
+ copy.reserve(totalShortcuts);
+
+ for (const auto& c : m_vClients) {
+ for (const auto& sh : c->shortcuts) {
copy.push_back(*sh);
}
}