Commit 86ae7b06 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

//components/google: use flat_set to hold static sets of strings.

It's more memory efficient than std::set. Also changes the sets to hold
StringPiece instead of std::string, since the sets only hold string
constants.

Change-Id: Ia5e8823e7285863724bb4a1956afaff2bc6186ea
Reviewed-on: https://chromium-review.googlesource.com/c/1298359Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602466}
parent 74d2668b
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#include <stddef.h> #include <stddef.h>
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/flat_set.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -116,9 +116,9 @@ bool IsCanonicalHostGoogleHostname(base::StringPiece canonical_host, ...@@ -116,9 +116,9 @@ bool IsCanonicalHostGoogleHostname(base::StringPiece canonical_host,
// same page. // same page.
StripTrailingDot(&tld); StripTrailingDot(&tld);
static base::NoDestructor<std::set<std::string>> google_tlds( static const base::NoDestructor<base::flat_set<base::StringPiece>>
std::initializer_list<std::string>({GOOGLE_TLD_LIST})); google_tlds(std::initializer_list<base::StringPiece>({GOOGLE_TLD_LIST}));
return base::ContainsKey(*google_tlds, tld.as_string()); return google_tlds->contains(tld);
} }
// True if |url| is a valid URL with a host that is in the static list of // True if |url| is a valid URL with a host that is in the static list of
...@@ -131,11 +131,11 @@ bool IsGoogleSearchSubdomainUrl(const GURL& url) { ...@@ -131,11 +131,11 @@ bool IsGoogleSearchSubdomainUrl(const GURL& url) {
base::StringPiece host(url.host_piece()); base::StringPiece host(url.host_piece());
StripTrailingDot(&host); StripTrailingDot(&host);
static base::NoDestructor<std::set<std::string>> google_subdomains( static const base::NoDestructor<base::flat_set<base::StringPiece>>
std::initializer_list<std::string>( google_subdomains(std::initializer_list<base::StringPiece>(
{"ipv4.google.com", "ipv6.google.com"})); {"ipv4.google.com", "ipv6.google.com"}));
return base::ContainsKey(*google_subdomains, host.as_string()); return google_subdomains->contains(host);
} }
} // namespace } // namespace
......
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