perf: avoid std::map
temporaries in WebContents::DevToolsRequestFileSystems()
(#46268)
* perf: move the GetDevToolsWebContents() call outside of the loop * perf: remove std::map temporary in WebContents::DevToolsRequestFileSystems() * refactor: remove unused GetAddedFileSystemPaths() * perf: remove std::vector temporary in WebContents::DevToolsRequestFileSystems()
This commit is contained in:
parent
3212f60d69
commit
3ae285b614
1 changed files with 13 additions and 33 deletions
|
@ -682,17 +682,6 @@ PrefService* GetPrefService(content::WebContents* web_contents) {
|
||||||
return GetPrefService(web_contents)->GetDict(prefs::kDevToolsFileSystemPaths);
|
return GetPrefService(web_contents)->GetDict(prefs::kDevToolsFileSystemPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::string> GetAddedFileSystemPaths(
|
|
||||||
content::WebContents* web_contents) {
|
|
||||||
std::map<std::string, std::string> result;
|
|
||||||
for (auto it : GetAddedFileSystems(web_contents)) {
|
|
||||||
std::string type =
|
|
||||||
it.second.is_string() ? it.second.GetString() : std::string();
|
|
||||||
result[it.first] = type;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsDevToolsFileSystemAdded(content::WebContents* web_contents,
|
bool IsDevToolsFileSystemAdded(content::WebContents* web_contents,
|
||||||
const std::string_view file_system_path) {
|
const std::string_view file_system_path) {
|
||||||
return GetAddedFileSystems(web_contents).contains(file_system_path);
|
return GetAddedFileSystems(web_contents).contains(file_system_path);
|
||||||
|
@ -4060,31 +4049,22 @@ void WebContents::DevToolsAppendToFile(const std::string& url,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::DevToolsRequestFileSystems() {
|
void WebContents::DevToolsRequestFileSystems() {
|
||||||
auto file_system_paths = GetAddedFileSystemPaths(GetDevToolsWebContents());
|
const std::string empty_str;
|
||||||
if (file_system_paths.empty()) {
|
content::WebContents* const dtwc = GetDevToolsWebContents();
|
||||||
inspectable_web_contents_->CallClientFunction(
|
const base::Value::Dict& added_paths = GetAddedFileSystems(dtwc);
|
||||||
"DevToolsAPI", "fileSystemsLoaded", base::Value(base::Value::List()));
|
|
||||||
return;
|
auto filesystems = base::Value::List::with_capacity(added_paths.size());
|
||||||
|
for (const auto path_and_type : added_paths) {
|
||||||
|
const auto& [path, type_val] = path_and_type;
|
||||||
|
const auto& type = type_val.is_string() ? type_val.GetString() : empty_str;
|
||||||
|
const std::string file_system_id =
|
||||||
|
RegisterFileSystem(dtwc, base::FilePath::FromUTF8Unsafe(path));
|
||||||
|
filesystems.Append(CreateFileSystemValue(
|
||||||
|
CreateFileSystemStruct(dtwc, file_system_id, path, type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FileSystem> file_systems;
|
|
||||||
for (const auto& file_system_path : file_system_paths) {
|
|
||||||
base::FilePath path =
|
|
||||||
base::FilePath::FromUTF8Unsafe(file_system_path.first);
|
|
||||||
std::string file_system_id =
|
|
||||||
RegisterFileSystem(GetDevToolsWebContents(), path);
|
|
||||||
FileSystem file_system =
|
|
||||||
CreateFileSystemStruct(GetDevToolsWebContents(), file_system_id,
|
|
||||||
file_system_path.first, file_system_path.second);
|
|
||||||
file_systems.push_back(file_system);
|
|
||||||
}
|
|
||||||
|
|
||||||
base::Value::List file_system_value;
|
|
||||||
for (const auto& file_system : file_systems)
|
|
||||||
file_system_value.Append(CreateFileSystemValue(file_system));
|
|
||||||
inspectable_web_contents_->CallClientFunction(
|
inspectable_web_contents_->CallClientFunction(
|
||||||
"DevToolsAPI", "fileSystemsLoaded",
|
"DevToolsAPI", "fileSystemsLoaded", base::Value{std::move(filesystems)});
|
||||||
base::Value(std::move(file_system_value)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::DevToolsAddFileSystem(
|
void WebContents::DevToolsAddFileSystem(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue