perf: avoid redundant map lookups in GetStorageMask() (#46345)

* perf: avoid a redundant map lookuop in GetStorageMask()

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

* perf: avoid a redundant map lookup in GetDataTypeMask()

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-28 10:57:59 -05:00 committed by GitHub
parent 46d9bd8b4a
commit b51d9976d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,7 @@
#include "base/command_line.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/map_util.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@ -141,9 +142,8 @@ uint32_t GetStorageMask(const std::vector<std::string>& storage_types) {
uint32_t storage_mask = 0;
for (const auto& it : storage_types) {
auto type = base::ToLowerASCII(it);
if (Lookup.contains(type))
storage_mask |= Lookup.at(type);
if (const uint32_t* val = base::FindOrNull(Lookup, base::ToLowerASCII(it)))
storage_mask |= *val;
}
return storage_mask;
}
@ -183,9 +183,8 @@ BrowsingDataRemover::DataType GetDataTypeMask(
const std::vector<std::string>& data_types) {
BrowsingDataRemover::DataType mask = 0u;
for (const auto& type : data_types) {
if (kDataTypeLookup.contains(type)) {
mask |= kDataTypeLookup.at(type);
}
if (const auto* val = base::FindOrNull(kDataTypeLookup, type))
mask |= *val;
}
return mask;
}