perf: avoid redundant map lookup in AddComponentResourceEntries()
(#46288)
* perf: avoid double map lookup in ElectronComponentExtensionResourceManager::AddComponentResourceEntries() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: move the path key when calling try_emplace() 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:
parent
44afb48112
commit
e0014f507f
1 changed files with 7 additions and 4 deletions
|
@ -84,12 +84,14 @@ void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
|
||||||
gen_folder_path = gen_folder_path.NormalizePathSeparators();
|
gen_folder_path = gen_folder_path.NormalizePathSeparators();
|
||||||
|
|
||||||
for (const auto& entry : entries) {
|
for (const auto& entry : entries) {
|
||||||
|
const int id = entry.id;
|
||||||
base::FilePath resource_path = base::FilePath().AppendASCII(entry.path);
|
base::FilePath resource_path = base::FilePath().AppendASCII(entry.path);
|
||||||
resource_path = resource_path.NormalizePathSeparators();
|
resource_path = resource_path.NormalizePathSeparators();
|
||||||
|
|
||||||
if (!gen_folder_path.IsParent(resource_path)) {
|
if (!gen_folder_path.IsParent(resource_path)) {
|
||||||
DCHECK(!path_to_resource_id_.contains(resource_path));
|
const auto [_, inserted] =
|
||||||
path_to_resource_id_[resource_path] = entry.id;
|
path_to_resource_id_.try_emplace(std::move(resource_path), id);
|
||||||
|
DCHECK(inserted);
|
||||||
} else {
|
} else {
|
||||||
// If the resource is a generated file, strip the generated folder's path,
|
// If the resource is a generated file, strip the generated folder's path,
|
||||||
// so that it can be served from a normal URL (as if it were not
|
// so that it can be served from a normal URL (as if it were not
|
||||||
|
@ -97,8 +99,9 @@ void ElectronComponentExtensionResourceManager::AddComponentResourceEntries(
|
||||||
base::FilePath effective_path =
|
base::FilePath effective_path =
|
||||||
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
|
base::FilePath().AppendASCII(resource_path.AsUTF8Unsafe().substr(
|
||||||
gen_folder_path.value().length()));
|
gen_folder_path.value().length()));
|
||||||
DCHECK(!path_to_resource_id_.contains(effective_path));
|
const auto [_, inserted] =
|
||||||
path_to_resource_id_[effective_path] = entry.id;
|
path_to_resource_id_.try_emplace(std::move(effective_path), id);
|
||||||
|
DCHECK(inserted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue