linker_namespace: move sonames instead of copying
android_namespace_link_t::shared_lib_sonames_ is unorderd_set<string>.
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
diff --git a/linker/linker.cpp b/linker/linker.cpp
index c10e9f6..6246f8c 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -39,6 +39,7 @@
#include <sys/vfs.h>
#include <unistd.h>
+#include <iterator>
#include <new>
#include <string>
#include <unordered_map>
@@ -2484,11 +2485,12 @@
return false;
}
- auto sonames = android::base::Split(shared_lib_sonames, ":");
- std::unordered_set<std::string> sonames_set(sonames.begin(), sonames.end());
+ std::vector<std::string> sonames = android::base::Split(shared_lib_sonames, ":");
+ std::unordered_set<std::string> 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;
}