Replace StringPiece with std::string_view in OatFile.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 123750182
Change-Id: Ia5a3c0bb5fdfba7cf88b82768c6722493e258554
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index d179b80..8a0a1e7 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -838,10 +838,10 @@
oat_dex_files_storage_.push_back(oat_dex_file);
// Add the location and canonical location (if different) to the oat_dex_files_ table.
- StringPiece key(oat_dex_file->GetDexFileLocation());
+ std::string_view key(oat_dex_file->GetDexFileLocation());
oat_dex_files_.Put(key, oat_dex_file);
if (canonical_location != dex_file_location) {
- StringPiece canonical_key(oat_dex_file->GetCanonicalDexFileLocation());
+ std::string_view canonical_key(oat_dex_file->GetCanonicalDexFileLocation());
oat_dex_files_.Put(canonical_key, oat_dex_file);
}
}
@@ -1664,7 +1664,7 @@
// without any performance loss, for example by not doing the first lock-free lookup.
const OatDexFile* oat_dex_file = nullptr;
- StringPiece key(dex_location);
+ std::string_view key(dex_location);
// Try to find the key cheaply in the oat_dex_files_ map which holds dex locations
// directly mentioned in the oat file and doesn't require locking.
auto primary_it = oat_dex_files_.find(key);
@@ -1683,7 +1683,7 @@
// We haven't seen this dex_location before, we must check the canonical location.
std::string dex_canonical_location = DexFileLoader::GetDexCanonicalLocation(dex_location);
if (dex_canonical_location != dex_location) {
- StringPiece canonical_key(dex_canonical_location);
+ std::string_view canonical_key(dex_canonical_location);
auto canonical_it = oat_dex_files_.find(canonical_key);
if (canonical_it != oat_dex_files_.end()) {
oat_dex_file = canonical_it->second;
@@ -1692,7 +1692,7 @@
// Copy the key to the string_cache_ and store the result in secondary map.
string_cache_.emplace_back(key.data(), key.length());
- StringPiece key_copy(string_cache_.back());
+ std::string_view key_copy(string_cache_.back());
secondary_oat_dex_files_.PutBefore(secondary_lb, key_copy, oat_dex_file);
}
}
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 1ba6e49..37dbe6a 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -19,13 +19,13 @@
#include <list>
#include <string>
+#include <string_view>
#include <vector>
#include "base/array_ref.h"
#include "base/mutex.h"
#include "base/os.h"
#include "base/safe_map.h"
-#include "base/stringpiece.h"
#include "base/tracking_safe_map.h"
#include "class_status.h"
#include "compiler_filter.h"
@@ -398,12 +398,13 @@
// Owning storage for the OatDexFile objects.
std::vector<const OatDexFile*> oat_dex_files_storage_;
- // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every
- // lookup with a const char* key. The StringPiece doesn't own its backing storage,
+ // NOTE: We use a std::string_view as the key type to avoid a memory allocation on every
+ // lookup with a const char* key. The std::string_view doesn't own its backing storage,
// therefore we're using the OatDexFile::dex_file_location_ as the backing storage
// for keys in oat_dex_files_ and the string_cache_ entries for the backing storage
// of keys in secondary_oat_dex_files_ and oat_dex_files_by_canonical_location_.
- typedef AllocationTrackingSafeMap<StringPiece, const OatDexFile*, kAllocatorTagOatFile> Table;
+ using Table =
+ AllocationTrackingSafeMap<std::string_view, const OatDexFile*, kAllocatorTagOatFile>;
// Map each location and canonical location (if different) retrieved from the
// oat file to its OatDexFile. This map doesn't change after it's constructed in Setup()
@@ -422,7 +423,7 @@
// Cache of strings. Contains the backing storage for keys in the secondary_oat_dex_files_
// and the lazily initialized oat_dex_files_by_canonical_location_.
- // NOTE: We're keeping references to contained strings in form of StringPiece and adding
+ // NOTE: We're keeping references to contained strings in form of std::string_view and adding
// new strings to the end. The adding of a new element must not touch any previously stored
// elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't.
mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_);