Do not resolve caller_ns when it is not needed
create_namespace resolves caller namespace only
when caller did not explicitly specify parent namespace.
This saves about 25 microseconds for the case when
parent_namepsace is not null (for example when creating
second classloader for the app).
Bug: http://b/28801010
Change-Id: I50ded272c931db701e5a1d8c88ed5ffb13416539
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 09286c0..719b00a 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -2417,7 +2417,7 @@
// is still pointing to the default one.
android_namespace_t* anon_ns =
create_namespace(nullptr, "(anonymous)", nullptr, anon_ns_library_path,
- ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
+ ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, &g_default_namespace);
if (anon_ns == nullptr) {
g_public_namespace_initialized = false;
@@ -2440,15 +2440,13 @@
return nullptr;
}
- soinfo* caller_soinfo = find_containing_library(caller_addr);
-
- android_namespace_t* caller_ns = caller_soinfo != nullptr ?
- caller_soinfo->get_primary_namespace() :
- g_anonymous_namespace;
-
- // if parent_namespace is nullptr -> set it to the caller namespace
if (parent_namespace == nullptr) {
- parent_namespace = caller_ns;
+ // if parent_namespace is nullptr -> set it to the caller namespace
+ soinfo* caller_soinfo = find_containing_library(caller_addr);
+
+ parent_namespace = caller_soinfo != nullptr ?
+ caller_soinfo->get_primary_namespace() :
+ g_anonymous_namespace;
}
ProtectedDataGuard guard;