summaryrefslogtreecommitdiff
path: root/libs/androidfw/StringPool.cpp
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2024-07-03 16:10:17 -0700
committer Yurii Zubrytskyi <zyy@google.com> 2024-07-06 13:12:33 +0000
commit1d6d8ac9feb221f47692250647269f3753bdee60 (patch)
tree763fb6e254e1a46e7db9d202b889541b46d8bd76 /libs/androidfw/StringPool.cpp
parente085542060f2e0e938a14e2dcc9121ca51625345 (diff)
[res] Simplify XmlPullParser::FindAttribute() and StringPool::Sort
1. FindAttribute used to do lots of work that C++17 does automatically 2. Use function_ref for a more efficient callback passing Test: aapt2_tests Flag: EXEMPT minor refactor Change-Id: I4f172cca16c05422992b107e347ed01479fff898
Diffstat (limited to 'libs/androidfw/StringPool.cpp')
-rw-r--r--libs/androidfw/StringPool.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/libs/androidfw/StringPool.cpp b/libs/androidfw/StringPool.cpp
index ad445c042e63..629f14683b19 100644
--- a/libs/androidfw/StringPool.cpp
+++ b/libs/androidfw/StringPool.cpp
@@ -297,24 +297,22 @@ void StringPool::Prune() {
template <typename E>
static void SortEntries(
std::vector<std::unique_ptr<E>>& entries,
- const std::function<int(const StringPool::Context&, const StringPool::Context&)>& cmp) {
+ base::function_ref<int(const StringPool::Context&, const StringPool::Context&)> cmp) {
using UEntry = std::unique_ptr<E>;
+ std::sort(entries.begin(), entries.end(), [cmp](const UEntry& a, const UEntry& b) -> bool {
+ int r = cmp(a->context, b->context);
+ if (r == 0) {
+ r = a->value.compare(b->value);
+ }
+ return r < 0;
+ });
+}
- if (cmp != nullptr) {
- std::sort(entries.begin(), entries.end(), [&cmp](const UEntry& a, const UEntry& b) -> bool {
- int r = cmp(a->context, b->context);
- if (r == 0) {
- r = a->value.compare(b->value);
- }
- return r < 0;
- });
- } else {
- std::sort(entries.begin(), entries.end(),
- [](const UEntry& a, const UEntry& b) -> bool { return a->value < b->value; });
- }
+void StringPool::Sort() {
+ Sort([](auto&&, auto&&) { return 0; });
}
-void StringPool::Sort(const std::function<int(const Context&, const Context&)>& cmp) {
+void StringPool::Sort(base::function_ref<int(const Context&, const Context&)> cmp) {
SortEntries(styles_, cmp);
SortEntries(strings_, cmp);
ReAssignIndices();