From bb882b4f3dae54f7b4e88375ad88a3f84582dc4e Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 25 Mar 2025 14:10:12 -0500 Subject: [PATCH] perf: avoid `std::map` temporaries in `IsDevToolsFileSystemAdded()` (#46267) * refactor: extract-method GetAddedFileSystems() Co-authored-by: Charles Kerr * refactor: use GetAddedFileSystems() in GetAddedFileSystemPaths() Co-authored-by: Charles Kerr * refactor: use GetAddedFileSystems() in IsDevToolsFileSystemAdded() Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/api/electron_api_web_contents.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index c01e3c5fda2a..2760da5f972e 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -675,13 +675,16 @@ PrefService* GetPrefService(content::WebContents* web_contents) { return static_cast(context)->prefs(); } +// returns a Dict of filesystem_path -> type +[[nodiscard]] const base::Value::Dict& GetAddedFileSystems( + content::WebContents* web_contents) { + return GetPrefService(web_contents)->GetDict(prefs::kDevToolsFileSystemPaths); +} + std::map GetAddedFileSystemPaths( content::WebContents* web_contents) { - auto* pref_service = GetPrefService(web_contents); - const base::Value::Dict& file_system_paths = - pref_service->GetDict(prefs::kDevToolsFileSystemPaths); std::map result; - for (auto it : file_system_paths) { + for (auto it : GetAddedFileSystems(web_contents)) { std::string type = it.second.is_string() ? it.second.GetString() : std::string(); result[it.first] = type; @@ -690,8 +693,8 @@ std::map GetAddedFileSystemPaths( } bool IsDevToolsFileSystemAdded(content::WebContents* web_contents, - const std::string& file_system_path) { - return GetAddedFileSystemPaths(web_contents).contains(file_system_path); + const std::string_view file_system_path) { + return GetAddedFileSystems(web_contents).contains(file_system_path); } content::RenderFrameHost* GetRenderFrameHost(