refactor: omit redundant map searches (#19929)
* refactor: don't walk maps twice to remove elements * refactor: don't walk maps twice to read elements * refactor: don't walk maps twice to insert elements * refactor: don't walk map 3x on UvTaskRunner timeout * refactor: more don't-walk-maps-twice cleanup * fixup! refactor: don't walk maps twice to insert elements * refactor: don't walk containers twice when erasing * refactor: omit excess lookups in RemoteObjectFreer
This commit is contained in:
parent
27ce6a9cd3
commit
987300c97a
14 changed files with 88 additions and 86 deletions
|
@ -176,21 +176,15 @@ void ProtocolNS::RegisterURLLoaderFactories(
|
|||
ProtocolError ProtocolNS::RegisterProtocol(ProtocolType type,
|
||||
const std::string& scheme,
|
||||
const ProtocolHandler& handler) {
|
||||
ProtocolError error = ProtocolError::OK;
|
||||
if (!base::Contains(handlers_, scheme))
|
||||
handlers_[scheme] = std::make_pair(type, handler);
|
||||
else
|
||||
error = ProtocolError::REGISTERED;
|
||||
return error;
|
||||
const bool added = base::TryEmplace(handlers_, scheme, type, handler).second;
|
||||
return added ? ProtocolError::OK : ProtocolError::REGISTERED;
|
||||
}
|
||||
|
||||
void ProtocolNS::UnregisterProtocol(const std::string& scheme,
|
||||
mate::Arguments* args) {
|
||||
ProtocolError error = ProtocolError::OK;
|
||||
if (base::Contains(handlers_, scheme))
|
||||
handlers_.erase(scheme);
|
||||
else
|
||||
error = ProtocolError::NOT_REGISTERED;
|
||||
const bool removed = handlers_.erase(scheme) != 0;
|
||||
const auto error =
|
||||
removed ? ProtocolError::OK : ProtocolError::NOT_REGISTERED;
|
||||
HandleOptionalCallback(args, error);
|
||||
}
|
||||
|
||||
|
@ -201,21 +195,16 @@ bool ProtocolNS::IsProtocolRegistered(const std::string& scheme) {
|
|||
ProtocolError ProtocolNS::InterceptProtocol(ProtocolType type,
|
||||
const std::string& scheme,
|
||||
const ProtocolHandler& handler) {
|
||||
ProtocolError error = ProtocolError::OK;
|
||||
if (!base::Contains(intercept_handlers_, scheme))
|
||||
intercept_handlers_[scheme] = std::make_pair(type, handler);
|
||||
else
|
||||
error = ProtocolError::INTERCEPTED;
|
||||
return error;
|
||||
const bool added =
|
||||
base::TryEmplace(intercept_handlers_, scheme, type, handler).second;
|
||||
return added ? ProtocolError::OK : ProtocolError::INTERCEPTED;
|
||||
}
|
||||
|
||||
void ProtocolNS::UninterceptProtocol(const std::string& scheme,
|
||||
mate::Arguments* args) {
|
||||
ProtocolError error = ProtocolError::OK;
|
||||
if (base::Contains(intercept_handlers_, scheme))
|
||||
intercept_handlers_.erase(scheme);
|
||||
else
|
||||
error = ProtocolError::NOT_INTERCEPTED;
|
||||
const bool removed = intercept_handlers_.erase(scheme) != 0;
|
||||
const auto error =
|
||||
removed ? ProtocolError::OK : ProtocolError::NOT_INTERCEPTED;
|
||||
HandleOptionalCallback(args, error);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue