refactor: replace use of insert for std::maps with try_emplace
This commit is contained in:
parent
a54d4d6754
commit
f3fb31914d
10 changed files with 18 additions and 18 deletions
|
|
@ -1100,10 +1100,10 @@ void KeyState::updateModifierKeyState(
|
||||||
deskflow::KeyMap::ButtonToKeyMap oldKeys;
|
deskflow::KeyMap::ButtonToKeyMap oldKeys;
|
||||||
deskflow::KeyMap::ButtonToKeyMap newKeys;
|
deskflow::KeyMap::ButtonToKeyMap newKeys;
|
||||||
for (const auto &[modifier, keyItem] : oldModifiers) {
|
for (const auto &[modifier, keyItem] : oldModifiers) {
|
||||||
oldKeys.insert(std::make_pair(keyItem.m_button, &keyItem));
|
oldKeys.try_emplace(keyItem.m_button, &keyItem);
|
||||||
}
|
}
|
||||||
for (const auto &[modifier, keyItem] : newModifiers) {
|
for (const auto &[modifier, keyItem] : newModifiers) {
|
||||||
newKeys.insert(std::make_pair(keyItem.m_button, &keyItem));
|
newKeys.try_emplace(keyItem.m_button, &keyItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the modifier buttons that were pressed or released
|
// get the modifier buttons that were pressed or released
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ void SocketMultiplexer::addSocket(ISocket *socket, ISocketMultiplexerJob *job)
|
||||||
// serviceThread().
|
// serviceThread().
|
||||||
JobCursor j = m_socketJobs.insert(m_socketJobs.end(), job);
|
JobCursor j = m_socketJobs.insert(m_socketJobs.end(), job);
|
||||||
m_update = true;
|
m_update = true;
|
||||||
m_socketJobMap.insert(std::make_pair(socket, j));
|
m_socketJobMap.try_emplace(socket, j);
|
||||||
} else {
|
} else {
|
||||||
if (JobCursor j = i->second; *j != job) {
|
if (JobCursor j = i->second; *j != job) {
|
||||||
delete *j;
|
delete *j;
|
||||||
|
|
|
||||||
|
|
@ -806,7 +806,7 @@ MSWindowsDesks::Desk *MSWindowsDesks::addDesk(const std::wstring &name, HDESK hd
|
||||||
desk->m_targetID = GetCurrentThreadId();
|
desk->m_targetID = GetCurrentThreadId();
|
||||||
desk->m_thread = new Thread(new TMethodJob<MSWindowsDesks>(this, &MSWindowsDesks::deskThread, desk));
|
desk->m_thread = new Thread(new TMethodJob<MSWindowsDesks>(this, &MSWindowsDesks::deskThread, desk));
|
||||||
waitForDesk();
|
waitForDesk();
|
||||||
m_desks.insert(std::make_pair(name, desk));
|
m_desks.try_emplace(name, desk);
|
||||||
return desk;
|
return desk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -595,7 +595,7 @@ uint32_t MSWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
m_hotKeys.insert(std::make_pair(id, HotKeyItem(vk, modifiers)));
|
m_hotKeys.try_emplace(id, HotKeyItem(vk, modifiers));
|
||||||
m_hotKeyToIDMap[HotKeyItem(vk, modifiers)] = id;
|
m_hotKeyToIDMap[HotKeyItem(vk, modifiers)] = id;
|
||||||
} else {
|
} else {
|
||||||
m_oldHotKeyIDs.push_back(id);
|
m_oldHotKeyIDs.push_back(id);
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ uint32_t OSXScreen::registerHotKey(KeyID key, KeyModifierMask mask)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hotKeys.insert(std::make_pair(id, HotKeyItem(ref, macKey, macMask)));
|
m_hotKeys.try_emplace(id, HotKeyItem(ref, macKey, macMask));
|
||||||
|
|
||||||
LOG_DEBUG(
|
LOG_DEBUG(
|
||||||
"registered hotkey %s (id=%04x mask=%04x) as id=%d", deskflow::KeyMap::formatKey(key, mask).c_str(), key, mask, id
|
"registered hotkey %s (id=%04x mask=%04x) as id=%d", deskflow::KeyMap::formatKey(key, mask).c_str(), key, mask, id
|
||||||
|
|
|
||||||
|
|
@ -701,7 +701,7 @@ void XWindowsClipboard::motifFillCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
// save it
|
// save it
|
||||||
motifFormats.insert(std::make_pair(motifFormat.m_type, data));
|
motifFormats.try_emplace(motifFormat.m_type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try each converter in order (because they're in order of
|
// try each converter in order (because they're in order of
|
||||||
|
|
|
||||||
|
|
@ -398,7 +398,7 @@ void XWindowsKeyState::updateKeysymMap(deskflow::KeyMap &keyMap)
|
||||||
for (unsigned int i = 0; i < 8; ++i) {
|
for (unsigned int i = 0; i < 8; ++i) {
|
||||||
const KeyCode *buttons = modifiers->modifiermap + i * modifiers->max_keypermod;
|
const KeyCode *buttons = modifiers->modifiermap + i * modifiers->max_keypermod;
|
||||||
for (int j = 0; j < modifiers->max_keypermod; ++j) {
|
for (int j = 0; j < modifiers->max_keypermod; ++j) {
|
||||||
modifierButtons.insert(std::make_pair(buttons[j], i));
|
modifierButtons.try_emplace(buttons[j], i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XFreeModifiermap(modifiers);
|
XFreeModifiermap(modifiers);
|
||||||
|
|
@ -722,7 +722,7 @@ void XWindowsKeyState::updateKeysymMapXKB(deskflow::KeyMap &keyMap)
|
||||||
|
|
||||||
// save modifier
|
// save modifier
|
||||||
m_modifierFromX[8 * group + j] |= (1u << modifierBit);
|
m_modifierFromX[8 * group + j] |= (1u << modifierBit);
|
||||||
m_modifierToX.insert(std::make_pair(1u << modifierBit, 1u << j));
|
m_modifierToX.try_emplace(1u << modifierBit, 1u << j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -431,7 +431,7 @@ void XWindowsScreenSaver::addWatchXScreenSaver(Window window)
|
||||||
}
|
}
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// if successful then add the window to our list
|
// if successful then add the window to our list
|
||||||
m_watchWindows.insert(std::make_pair(window, attr.your_event_mask));
|
m_watchWindows.try_emplace(window, attr.your_event_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ bool Config::addScreen(const std::string &name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add cell
|
// add cell
|
||||||
m_map.insert(std::make_pair(name, Cell()));
|
m_map.try_emplace(name, Cell());
|
||||||
|
|
||||||
// add name
|
// add name
|
||||||
m_nameToCanonicalName.insert(std::make_pair(name, name));
|
m_nameToCanonicalName.try_emplace(name, name);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -67,11 +67,11 @@ bool Config::renameScreen(const std::string &oldName, const std::string &newName
|
||||||
// update cell
|
// update cell
|
||||||
Cell tmpCell = index->second;
|
Cell tmpCell = index->second;
|
||||||
m_map.erase(index);
|
m_map.erase(index);
|
||||||
m_map.insert(std::make_pair(newName, tmpCell));
|
m_map.try_emplace(newName, tmpCell);
|
||||||
|
|
||||||
// update name
|
// update name
|
||||||
m_nameToCanonicalName.erase(oldCanonical);
|
m_nameToCanonicalName.erase(oldCanonical);
|
||||||
m_nameToCanonicalName.insert(std::make_pair(newName, newName));
|
m_nameToCanonicalName.try_emplace(newName, newName);
|
||||||
|
|
||||||
// update connections
|
// update connections
|
||||||
Name oldNameObj(this, oldName);
|
Name oldNameObj(this, oldName);
|
||||||
|
|
@ -138,7 +138,7 @@ bool Config::addAlias(const std::string &canonical, const std::string &alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert alias
|
// insert alias
|
||||||
m_nameToCanonicalName.insert(std::make_pair(alias, canonical));
|
m_nameToCanonicalName.try_emplace(alias, canonical);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1442,7 +1442,7 @@ bool Config::Cell::add(const CellEdge &src, const CellEdge &dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_neighbors.erase(src);
|
m_neighbors.erase(src);
|
||||||
m_neighbors.insert(std::make_pair(src, dst));
|
m_neighbors.try_emplace(src, dst);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1907,7 +1907,7 @@ bool Server::addClient(BaseClientProxy *client)
|
||||||
|
|
||||||
// add to list
|
// add to list
|
||||||
m_clientSet.insert(client);
|
m_clientSet.insert(client);
|
||||||
m_clients.insert(std::make_pair(name, client));
|
m_clients.try_emplace(name, client);
|
||||||
|
|
||||||
// initialize client data
|
// initialize client data
|
||||||
int32_t x;
|
int32_t x;
|
||||||
|
|
@ -1970,7 +1970,7 @@ void Server::closeClient(BaseClientProxy *client, const char *msg)
|
||||||
// move client to closing list
|
// move client to closing list
|
||||||
removeClient(client);
|
removeClient(client);
|
||||||
|
|
||||||
m_oldClients.insert(std::make_pair(client, timer));
|
m_oldClients.try_emplace(client, timer);
|
||||||
|
|
||||||
// if this client is the active screen then we have to
|
// if this client is the active screen then we have to
|
||||||
// jump off of it
|
// jump off of it
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue