Do not use std::vector in android_namespace_t::is_accessible

Avoid constructing vector and walking all the parents of a soinfo
to check if it is accessible. The most likely scenario that the
very first check returns true.

Bug: http://b/35313368
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: I06c65cf61ed1c30e5e454a169de4c41038863587
diff --git a/linker/linker_namespaces.cpp b/linker/linker_namespaces.cpp
index a7e14cc..273ff9b 100644
--- a/linker/linker_namespaces.cpp
+++ b/linker/linker_namespaces.cpp
@@ -30,8 +30,6 @@
 #include "linker_soinfo.h"
 #include "linker_utils.h"
 
-#include <vector>
-
 bool android_namespace_t::is_accessible(const std::string& file) {
   if (!is_isolated_) {
     return true;
@@ -59,13 +57,7 @@
 }
 
 bool android_namespace_t::is_accessible(soinfo* s) {
-  std::vector<soinfo*> soinfos;
-  soinfos.push_back(s);
-  s->get_parents().for_each([&](soinfo* parent_si) {
-    soinfos.push_back(parent_si);
-  });
-
-  return std::find_if(soinfos.begin(), soinfos.end(), [this](soinfo* si) {
+  auto is_accessible_ftor = [this] (soinfo* si) {
     if (si->get_primary_namespace() == this) {
       return true;
     }
@@ -76,5 +68,13 @@
     }
 
     return false;
-  }) != soinfos.end();
+  };
+
+  if (is_accessible_ftor(s)) {
+    return true;
+  }
+
+  return !s->get_parents().visit([&](soinfo* si) {
+    return !is_accessible_ftor(si);
+  });
 }