Commit e8204d4a authored by Jeremy Roman's avatar Jeremy Roman Committed by Chromium LUCI CQ

printing: Efficiently construct flat_map in GetPrinterRecentlyUsedRanks.

flat_map can be more efficiently constructed when it only has to sort
once, which can be done by constructing the initial data in a vector
(and ideally, as here, by reserving its capacity).

Change-Id: Iea865434fe17c7b06a21d62565b447332c521cca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2605881
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840420}
parent dc041de0
......@@ -57,10 +57,12 @@ void PrintPreviewStickySettings::RestoreFromPrefs(PrefService* prefs) {
base::flat_map<std::string, int>
PrintPreviewStickySettings::GetPrinterRecentlyUsedRanks() {
auto recently_used_printers = GetRecentlyUsedPrinters();
int current_rank = 0;
base::flat_map<std::string, int> recently_used_ranks;
for (const std::string& printer_id : GetRecentlyUsedPrinters())
recently_used_ranks[printer_id] = current_rank++;
std::vector<std::pair<std::string, int>> recently_used_ranks;
recently_used_ranks.reserve(recently_used_printers.size());
for (std::string& printer_id : recently_used_printers)
recently_used_ranks.emplace_back(std::move(printer_id), current_rank++);
return recently_used_ranks;
}
......
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