Commit 3348fd5c authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Use base::flat_[set|map] over std::[set|map] in Print Preview UI

For small maps and sets that contain efficiently moveable items,
base::flat_[set|map] performs inserts better than std::[set|map],
because the former avoids mallocs. Additionally, base::flat_[set|map]
has a smaller overhead than its STL counterpart. Usage recommendation
can be found at base/containers/README.md.

All the substitutions in this CL are made on containers that are
expected to be small (< dozens of entries) and that hold light and
easily moveable items.

Change-Id: I2fe35182cd7c85479db4b7b6343ea9af031031ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925438
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718312}
parent 260682df
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/i18n/number_formatting.h" #include "base/i18n/number_formatting.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
#ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_PRINT_PREVIEW_HANDLER_H_
#include <map>
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -353,13 +353,13 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, ...@@ -353,13 +353,13 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
std::unique_ptr<PrinterHandler> local_printer_handler_; std::unique_ptr<PrinterHandler> local_printer_handler_;
// Maps preview request ids to callbacks. // Maps preview request ids to callbacks.
std::map<int, std::string> preview_callbacks_; base::flat_map<int, std::string> preview_callbacks_;
// Set of preview request ids for failed previews. // Set of preview request ids for failed previews.
std::set<int> preview_failures_; base::flat_set<int> preview_failures_;
// Set of printer types on the deny list. // Set of printer types on the deny list.
std::set<PrinterType> printer_type_deny_list_; base::flat_set<PrinterType> printer_type_deny_list_;
base::WeakPtrFactory<PrintPreviewHandler> weak_factory_{this}; base::WeakPtrFactory<PrintPreviewHandler> weak_factory_{this};
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
#include <map>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/flat_map.h"
#include "base/containers/id_map.h" #include "base/containers/id_map.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -90,7 +90,7 @@ constexpr char kGeneratedPath[] = ...@@ -90,7 +90,7 @@ constexpr char kGeneratedPath[] =
PrintPreviewUI::TestDelegate* g_test_delegate = nullptr; PrintPreviewUI::TestDelegate* g_test_delegate = nullptr;
// Thread-safe wrapper around a std::map to keep track of mappings from // Thread-safe wrapper around a base::flat_map to keep track of mappings from
// PrintPreviewUI IDs to most recent print preview request IDs. // PrintPreviewUI IDs to most recent print preview request IDs.
class PrintPreviewRequestIdMapWithLock { class PrintPreviewRequestIdMapWithLock {
public: public:
...@@ -122,7 +122,7 @@ class PrintPreviewRequestIdMapWithLock { ...@@ -122,7 +122,7 @@ class PrintPreviewRequestIdMapWithLock {
private: private:
// Mapping from PrintPreviewUI ID to print preview request ID. // Mapping from PrintPreviewUI ID to print preview request ID.
typedef std::map<int, int> PrintPreviewRequestIdMap; using PrintPreviewRequestIdMap = base::flat_map<int, int>;
PrintPreviewRequestIdMap map_; PrintPreviewRequestIdMap map_;
base::Lock lock_; base::Lock lock_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment