From 3ff5c4ea5f251af5fdb68abf7796d4ec1b916547 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 26 Mar 2025 18:34:37 -0500 Subject: [PATCH] perf: avoid redundant map lookup in `WebContents::DevToolsIndexPath()` (#46295) perf: avoid double map lookup in WebContents::DevToolsIndexPath() Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- .../browser/api/electron_api_web_contents.cc | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index a5b7026d0eb3..ad4b2e7c0fad 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -4139,8 +4139,11 @@ void WebContents::DevToolsIndexPath( OnDevToolsIndexingDone(request_id, file_system_path); return; } - if (devtools_indexing_jobs_.contains(request_id)) + + auto& indexing_job = devtools_indexing_jobs_[request_id]; + if (indexing_job) return; + std::vector excluded_folders; std::optional parsed_excluded_folders = base::JSONReader::Read(excluded_folders_message); @@ -4150,19 +4153,18 @@ void WebContents::DevToolsIndexPath( excluded_folders.push_back(folder_path.GetString()); } } - devtools_indexing_jobs_[request_id] = - scoped_refptr( - devtools_file_system_indexer_->IndexPath( - file_system_path, excluded_folders, - base::BindRepeating( - &WebContents::OnDevToolsIndexingWorkCalculated, - weak_factory_.GetWeakPtr(), request_id, file_system_path), - base::BindRepeating(&WebContents::OnDevToolsIndexingWorked, - weak_factory_.GetWeakPtr(), request_id, - file_system_path), - base::BindRepeating(&WebContents::OnDevToolsIndexingDone, - weak_factory_.GetWeakPtr(), request_id, - file_system_path))); + + indexing_job = devtools_file_system_indexer_->IndexPath( + file_system_path, excluded_folders, + base::BindRepeating(&WebContents::OnDevToolsIndexingWorkCalculated, + weak_factory_.GetWeakPtr(), request_id, + file_system_path), + base::BindRepeating(&WebContents::OnDevToolsIndexingWorked, + weak_factory_.GetWeakPtr(), request_id, + file_system_path), + base::BindRepeating(&WebContents::OnDevToolsIndexingDone, + weak_factory_.GetWeakPtr(), request_id, + file_system_path)); } void WebContents::DevToolsStopIndexing(int request_id) {