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

* refactor: extract-method GetAddedFileSystems()

* refactor: use GetAddedFileSystems() in GetAddedFileSystemPaths()

* refactor: use GetAddedFileSystems() in IsDevToolsFileSystemAdded()
This commit is contained in:
Charles Kerr 2025-03-25 11:42:58 -05:00 committed by GitHub
parent f7ba0d3b4b
commit ced8fdbce8
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(