prefs: Use StringPiece instead of string& to avoid allocation
Currently, PrefService::GetValue and related functions take path
arguments as `const std::string&`. Since most call sites actually
pass `const char*` parameters, this leads to a lot of string constructions and (potentially) memory allocations, depending on the size of the string.
This CL replaces the argument type with `base::StringPiece`, which reduces the Android binary size by about 11kB.
In order to look up `base::StringPiece` keys in
`std::set<std::string>` or `std::map<std::string, base::Value>` we
need to replace the Compare function object with `std::less<void>`, which allows transparent comparison.
This is defined in the new header components/prefs/pref_name_set.h
Bug: 1366031
Change-Id: I386f032849fb75c8416047e48ecc92b567faf450
Tests: Existing unit tests
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3902702
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Igor <[email protected]>
Reviewed-by: Sean Topping <[email protected]>
Commit-Queue: Roland Bock <[email protected]>
Reviewed-by: Dominic Battré <[email protected]>
Reviewed-by: Michael Bai <[email protected]>
Reviewed-by: Aga Wronska <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1051089}
diff --git a/components/prefs/BUILD.gn b/components/prefs/BUILD.gn
index 43ff647f..2d48b09 100644
--- a/components/prefs/BUILD.gn
+++ b/components/prefs/BUILD.gn
@@ -23,6 +23,7 @@
"pref_filter.h",
"pref_member.cc",
"pref_member.h",
+ "pref_name_set.h",
"pref_notifier.h",
"pref_notifier_impl.cc",
"pref_notifier_impl.h",