string_view: handle with care.
Don't create temporary std::strings in InitializeApexVersions as we're
using string_view of these strings in maps.
Test: test.py, asan build
Bug: 186883886
Change-Id: I6129dee4a06db3cf2bd73157da5b40b67704cbfb
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index f111ff8..f6429f8 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1240,7 +1240,7 @@
void Runtime::InitializeApexVersions() {
std::vector<std::string_view> bcp_apexes;
- for (const std::string& jar : Runtime::Current()->GetBootClassPathLocations()) {
+ for (std::string_view jar : Runtime::Current()->GetBootClassPathLocations()) {
if (LocationIsOnApex(jar)) {
size_t start = jar.find('/', 1);
if (start == std::string::npos) {
@@ -1250,7 +1250,7 @@
if (end == std::string::npos) {
continue;
}
- std::string apex = jar.substr(start + 1, end - start - 1);
+ std::string_view apex = jar.substr(start + 1, end - start - 1);
bcp_apexes.push_back(apex);
}
}