Commit 77b8dd53 authored by Denis Yaroshevskiy's avatar Denis Yaroshevskiy Committed by Commit Bot

Using a flat_set to get rid of const_cast.

TemplateURLSet should be small enougth to use flat_set.
When implementing flat_sets, we specificly desided to provide a different
solution for Librayr Working Group issue: #2059, which allows to just
remove the const_cast.

Here is a test for it:
https://cs.chromium.org/chromium/src/base/containers/flat_tree_unittest.cc?sq=package:chromium&l=962

Change-Id: I4dfd5f3a5510c11ca4ef325dd0cb1e74fc7735f4
Reviewed-on: https://chromium-review.googlesource.com/995279Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Denis Yaroshevskiy <dyaroshev@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#548031}
parent c0791537
...@@ -45,8 +45,7 @@ void SearchHostToURLsMap::Remove(const TemplateURL* template_url) { ...@@ -45,8 +45,7 @@ void SearchHostToURLsMap::Remove(const TemplateURL* template_url) {
auto set_with_url = auto set_with_url =
std::find_if(host_to_urls_map_.begin(), host_to_urls_map_.end(), std::find_if(host_to_urls_map_.begin(), host_to_urls_map_.end(),
[&](std::pair<const std::string, TemplateURLSet>& entry) { [&](std::pair<const std::string, TemplateURLSet>& entry) {
return entry.second.erase( return entry.second.erase(template_url);
const_cast<TemplateURL*>(template_url));
}); });
if (set_with_url != host_to_urls_map_.end() && set_with_url->second.empty()) if (set_with_url != host_to_urls_map_.end() && set_with_url->second.empty())
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include <functional> #include <functional>
#include <map> #include <map>
#include <set>
#include <string> #include <string>
#include "base/containers/flat_set.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// caller to ensure the right lifetime of them. // caller to ensure the right lifetime of them.
class SearchHostToURLsMap { class SearchHostToURLsMap {
public: public:
typedef std::set<TemplateURL*> TemplateURLSet; using TemplateURLSet = base::flat_set<TemplateURL*>;
SearchHostToURLsMap(); SearchHostToURLsMap();
~SearchHostToURLsMap(); ~SearchHostToURLsMap();
......
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