Skip to content

Commit a03a803

Browse files
cobalt: Remove redundant map search (youtube#9189)
The original code performed two map lookups to retrieve resource contents: first with base::Contains and then with resource_map.at. This change replaces that with a single call to base::FindOrNull. This optimizes the resource lookup process by eliminating a redundant map search, improving efficiency without altering behavior. Issue: 454630524
1 parent 210c237 commit a03a803

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cobalt/shell/browser/h5vcc_scheme_url_loader_factory.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "base/base64.h"
2121
#include "base/containers/contains.h"
22+
#include "base/containers/map_util.h"
2223
#include "base/containers/span.h"
2324
#include "base/strings/string_util.h"
2425
#include "base/strings/stringprintf.h"
@@ -231,10 +232,11 @@ class H5vccSchemeURLLoader : public network::mojom::URLLoader {
231232
resource_key = std::move(fallback);
232233
}
233234

234-
if (base::Contains(resource_map, resource_key)) {
235-
FileContents file_contents = resource_map.at(resource_key);
236-
content_ = std::string(reinterpret_cast<const char*>(file_contents.data),
237-
file_contents.size);
235+
if (const FileContents* file_contents_ptr =
236+
base::FindOrNull(resource_map, resource_key)) {
237+
content_ =
238+
std::string(reinterpret_cast<const char*>(file_contents_ptr->data),
239+
file_contents_ptr->size);
238240
} else {
239241
LOG(WARNING) << "Resource not found: " << resource_key;
240242
}

0 commit comments

Comments
 (0)