perf: avoid std::map temporaries in IsDevToolsFileSystemAdded() (#46265)

* refactor: extract-method GetAddedFileSystems()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use GetAddedFileSystems() in GetAddedFileSystemPaths()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use GetAddedFileSystems() in IsDevToolsFileSystemAdded()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-03-25 14:09:55 -05:00 committed by GitHub
parent d38c2d507e
commit ac22aa932f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -676,13 +676,16 @@ PrefService* GetPrefService(content::WebContents* web_contents) {
return static_cast<electron::ElectronBrowserContext*>(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<std::string, std::string> 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<std::string, std::string> 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;
@ -691,8 +694,8 @@ std::map<std::string, std::string> 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(