From 57b03decd1ec98aa2577f3fa001a5fb4f769ef8f Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 1 Dec 2022 16:23:03 +0900 Subject: [PATCH] linker_namespace: move sonames instead of copying android_namespace_link_t::shared_lib_sonames_ is unorderd_set. When initializing, it's copied a few times unnecessarily. - when add_linked_namespace is called - when android_namespace_link_t() is called - when push_back is called. Now, it's moved around after the initial creation. Bug: n/a Test: atest --test-mapping . Change-Id: I283954bb0c0bbf94ebd74407137f492e08fd41bd --- linker/linker.cpp | 8 +++++--- linker/linker_namespaces.h | 14 +++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index c10e9f668..6246f8c20 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -2484,11 +2485,12 @@ bool link_namespaces(android_namespace_t* namespace_from, return false; } - auto sonames = android::base::Split(shared_lib_sonames, ":"); - std::unordered_set sonames_set(sonames.begin(), sonames.end()); + std::vector sonames = android::base::Split(shared_lib_sonames, ":"); + std::unordered_set sonames_set(std::make_move_iterator(sonames.begin()), + std::make_move_iterator(sonames.end())); ProtectedDataGuard guard; - namespace_from->add_linked_namespace(namespace_to, sonames_set, false); + namespace_from->add_linked_namespace(namespace_to, std::move(sonames_set), false); return true; } diff --git a/linker/linker_namespaces.h b/linker/linker_namespaces.h index 6817901a3..671e0b57e 100644 --- a/linker/linker_namespaces.h +++ b/linker/linker_namespaces.h @@ -41,11 +41,11 @@ struct android_namespace_t; struct android_namespace_link_t { public: android_namespace_link_t(android_namespace_t* linked_namespace, - const std::unordered_set& shared_lib_sonames, + std::unordered_set shared_lib_sonames, bool allow_all_shared_libs) - : linked_namespace_(linked_namespace), shared_lib_sonames_(shared_lib_sonames), - allow_all_shared_libs_(allow_all_shared_libs) - {} + : linked_namespace_(linked_namespace), + shared_lib_sonames_(std::move(shared_lib_sonames)), + allow_all_shared_libs_(allow_all_shared_libs) {} android_namespace_t* linked_namespace() const { return linked_namespace_; @@ -127,10 +127,10 @@ struct android_namespace_t { return linked_namespaces_; } void add_linked_namespace(android_namespace_t* linked_namespace, - const std::unordered_set& shared_lib_sonames, + std::unordered_set shared_lib_sonames, bool allow_all_shared_libs) { - linked_namespaces_.push_back( - android_namespace_link_t(linked_namespace, shared_lib_sonames, allow_all_shared_libs)); + linked_namespaces_.emplace_back(linked_namespace, std::move(shared_lib_sonames), + allow_all_shared_libs); } void add_soinfo(soinfo* si) {