mirror of https://github.com/AxioDL/boo.git
DeviceFinder: Invert conditionals within _insertToken and _removeToken
By converting the conditions into guard clauses, we can eliminate some code nesting.
This commit is contained in:
parent
9853a97dd2
commit
6cc5b30127
|
@ -36,19 +36,23 @@ DeviceFinder::~DeviceFinder() {
|
|||
}
|
||||
|
||||
bool DeviceFinder::_insertToken(std::unique_ptr<DeviceToken>&& token) {
|
||||
if (DeviceSignature::DeviceMatchToken(*token, m_types)) {
|
||||
if (!DeviceSignature::DeviceMatchToken(*token, m_types)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_tokensLock.lock();
|
||||
TInsertedDeviceToken insertedTok = m_tokens.insert(std::make_pair(token->getDevicePath(), std::move(token)));
|
||||
m_tokensLock.unlock();
|
||||
deviceConnected(*insertedTok.first->second);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeviceFinder::_removeToken(const std::string& path) {
|
||||
auto preCheck = m_tokens.find(path);
|
||||
if (preCheck != m_tokens.end()) {
|
||||
const auto preCheck = m_tokens.find(path);
|
||||
if (preCheck == m_tokens.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceToken& tok = *preCheck->second;
|
||||
std::shared_ptr<DeviceBase> dev = tok.m_connectedDev;
|
||||
tok._deviceClose();
|
||||
|
@ -56,7 +60,6 @@ void DeviceFinder::_removeToken(const std::string& path) {
|
|||
m_tokensLock.lock();
|
||||
m_tokens.erase(preCheck);
|
||||
m_tokensLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
bool DeviceFinder::startScanning() {
|
||||
|
|
Loading…
Reference in New Issue