There a a couple of redundant map lookups in QuicStreamFactory.
In the code snippet below, there are 5 job_requests_map_[server_id] lookups when we only need 1.
void QuicStreamFactory::OnJobComplete(Job* job, int rv) {
// Copy |server_id|, because |job| might be destroyed before this method
// returns.
const QuicServerId server_id(job->key().server_id());
if (rv != OK) {
JobSet* jobs = &(active_jobs_[server_id]);
if (jobs->size() > 1) {
// If there is another pending job, then we can delete this job and let
// the other job handle the request.
job->Cancel();
jobs->erase(job);
return;
}
}
if (rv == OK) {
if (!always_require_handshake_confirmation_)
set_require_confirmation(false);
if (!job_requests_map_[server_id].empty()) {
SessionMap::iterator session_it = active_sessions_.find(server_id);
DCHECK(session_it != active_sessions_.end());
QuicChromiumClientSession* session = session_it->second;
for (QuicStreamRequest* request : job_requests_map_[server_id]) {
DCHECK(request->server_id() == server_id);
// Do not notify |request| yet.
request->SetSession(session);
}
}
}
while (!job_requests_map_[server_id].empty()) {
RequestSet::iterator it = job_requests_map_[server_id].begin();
QuicStreamRequest* request = *it;
job_requests_map_[server_id].erase(it);
active_requests_.erase(request);
// Even though we're invoking callbacks here, we don't need to worry
// about |this| being deleted, because the factory is owned by the
// profile which can not be deleted via callbacks.
request->OnRequestComplete(rv);
}
for (auto& other_job : active_jobs_[server_id]) {
if (other_job.first != job)
other_job.first->Cancel();
}
active_jobs_[server_id].clear();
active_jobs_.erase(server_id);
job_requests_map_.erase(server_id);
}
Comment 1 by bugdroid1@chromium.org
, Apr 5 2017