diff options
author | 2023-11-09 16:03:45 +0000 | |
---|---|---|
committer | 2023-11-09 18:18:13 +0000 | |
commit | 18d2c1f61aac37d1e4f73a1acc1ba1d2b746cdef (patch) | |
tree | b0115281a1a3c9edbbbd5748259c3bd11cbc6065 | |
parent | 47d81c4136e125f4ac45f21d51d95c3cf2cc3890 (diff) |
Change IsMultiDexLocation to std::string_view
Test: ./art/test.py -b --host --optimizing --64
Change-Id: I70ffa88d30f3b43cc36161ed81a2722bbf4c3bb7
-rw-r--r-- | dex2oat/dex2oat.cc | 2 | ||||
-rw-r--r-- | libdexfile/dex/dex_file_loader.cc | 4 | ||||
-rw-r--r-- | libdexfile/dex/dex_file_loader.h | 3 | ||||
-rw-r--r-- | runtime/class_loader_context.cc | 2 | ||||
-rw-r--r-- | runtime/gc/space/image_space.cc | 8 | ||||
-rw-r--r-- | runtime/native/java_lang_VMClassLoader.cc | 2 | ||||
-rw-r--r-- | runtime/oat_file.cc | 2 | ||||
-rw-r--r-- | runtime/runtime.cc | 12 |
8 files changed, 18 insertions, 17 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 33f8a43461..68a7d02fb9 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -1581,7 +1581,7 @@ class Dex2Oat final { LOG(ERROR) << "Missing dex file for boot class component " << bcp_location; return dex2oat::ReturnCode::kOther; } - CHECK(!DexFileLoader::IsMultiDexLocation(bcp_dex_files[bcp_df_pos]->GetLocation().c_str())); + CHECK(!DexFileLoader::IsMultiDexLocation(bcp_dex_files[bcp_df_pos]->GetLocation())); ++bcp_df_pos; while (bcp_df_pos != bcp_df_end && DexFileLoader::IsMultiDexLocation(bcp_dex_files[bcp_df_pos]->GetLocation().c_str())) { diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc index 0fc99357e3..0266c41726 100644 --- a/libdexfile/dex/dex_file_loader.cc +++ b/libdexfile/dex/dex_file_loader.cc @@ -141,8 +141,8 @@ bool DexFileLoader::IsVersionAndMagicValid(const uint8_t* magic) { return false; } -bool DexFileLoader::IsMultiDexLocation(const char* location) { - return strrchr(location, kMultiDexSeparator) != nullptr; +bool DexFileLoader::IsMultiDexLocation(std::string_view location) { + return location.find(kMultiDexSeparator) != std::string_view::npos; } std::string DexFileLoader::GetMultiDexClassesDexName(size_t index) { diff --git a/libdexfile/dex/dex_file_loader.h b/libdexfile/dex/dex_file_loader.h index be3359b98f..1cc7d4a87a 100644 --- a/libdexfile/dex/dex_file_loader.h +++ b/libdexfile/dex/dex_file_loader.h @@ -22,6 +22,7 @@ #include <memory> #include <optional> #include <string> +#include <string_view> #include <vector> #include "base/os.h" @@ -61,7 +62,7 @@ class DexFileLoader { // Check whether a location denotes a multidex dex file. This is a very simple check: returns // whether the string contains the separator character. - static bool IsMultiDexLocation(const char* location); + static bool IsMultiDexLocation(std::string_view location); // Return the name of the index-th classes.dex in a multidex zip file. This is classes.dex for // index == 0, and classes{index + 1}.dex else. diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc index 3bb7e426a1..afdbb4a38a 100644 --- a/runtime/class_loader_context.cc +++ b/runtime/class_loader_context.cc @@ -699,7 +699,7 @@ void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info, for (size_t k = 0; k < info.opened_dex_files.size();) { const std::unique_ptr<const DexFile>& dex_file = info.opened_dex_files[k]; uint32_t checksum = DexFileLoader::GetMultiDexChecksum(info.opened_dex_files, &k); - CHECK(!DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str())); + CHECK(!DexFileLoader::IsMultiDexLocation(dex_file->GetLocation())); if (for_dex2oat) { // De-duplicate locations. diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index 003a319292..5fec7b7bd6 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -3470,7 +3470,7 @@ bool ImageSpace::ValidateOatFile(const OatFile& oat_file, File& dex_file = dex_file_index < dex_files.size() ? dex_files[dex_file_index] : no_file; dex_file_index++; - if (DexFileLoader::IsMultiDexLocation(oat_dex_files[i]->GetDexFileLocation().c_str())) { + if (DexFileLoader::IsMultiDexLocation(oat_dex_files[i]->GetDexFileLocation())) { return false; // Expected primary dex file. } uint32_t oat_checksum = DexFileLoader::GetMultiDexChecksum(oat_dex_files, &i); @@ -3546,7 +3546,7 @@ std::string ImageSpace::GetBootClassPathChecksums( ArrayRef<const DexFile* const> boot_class_path_tail = ArrayRef<const DexFile* const>(boot_class_path).SubArray(bcp_pos); DCHECK(boot_class_path_tail.empty() || - !DexFileLoader::IsMultiDexLocation(boot_class_path_tail.front()->GetLocation().c_str())); + !DexFileLoader::IsMultiDexLocation(boot_class_path_tail.front()->GetLocation())); for (size_t i = 0; i < boot_class_path_tail.size();) { uint32_t checksum = DexFileLoader::GetMultiDexChecksum(boot_class_path_tail, &i); if (!boot_image_checksum.empty()) { @@ -3654,11 +3654,11 @@ bool ImageSpace::VerifyBootClassPathChecksums( CHECK_NE(num_dex_files, 0u); const std::string main_location = oat_file->GetOatDexFiles()[0]->GetDexFileLocation(); CHECK_EQ(main_location, boot_class_path_locations[bcp_pos + space_index]); - CHECK(!DexFileLoader::IsMultiDexLocation(main_location.c_str())); + CHECK(!DexFileLoader::IsMultiDexLocation(main_location)); size_t num_base_locations = 1u; for (size_t i = 1u; i != num_dex_files; ++i) { if (!DexFileLoader::IsMultiDexLocation( - oat_file->GetOatDexFiles()[i]->GetDexFileLocation().c_str())) { + oat_file->GetOatDexFiles()[i]->GetDexFileLocation())) { CHECK_EQ(image_space_count, 1u); // We can find base locations only for --single-image. ++num_base_locations; } diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc index b9c72b82e7..4dad46fb8c 100644 --- a/runtime/native/java_lang_VMClassLoader.cc +++ b/runtime/native/java_lang_VMClassLoader.cc @@ -134,7 +134,7 @@ static jobjectArray VMClassLoader_getBootClassPathEntries(JNIEnv* env, jclass) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); const std::vector<const DexFile*>& path = class_linker->GetBootClassPath(); auto is_base_dex = [](const DexFile* dex_file) { - return !DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str()); + return !DexFileLoader::IsMultiDexLocation(dex_file->GetLocation()); }; size_t jar_count = std::count_if(path.begin(), path.end(), is_base_dex); diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index 015851224e..4cee0d4f71 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -692,7 +692,7 @@ bool OatFileBase::Setup(int zip_fd, // Location encoded in the oat file. We will use this for multidex naming. std::string_view oat_dex_file_location(dex_file_location_data, dex_file_location_size); std::string dex_file_location(oat_dex_file_location); - bool is_multidex = DexFileLoader::IsMultiDexLocation(dex_file_location.c_str()); + bool is_multidex = DexFileLoader::IsMultiDexLocation(dex_file_location); // Check that `is_multidex` does not clash with other indicators. The first dex location // must be primary location and, if we're opening external dex files, the location must // be multi-dex if and only if we already have a dex file opened for it. diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 01aea2873a..93cf5cbade 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -3584,10 +3584,10 @@ bool Runtime::HasImageWithProfile() const { } void Runtime::AppendToBootClassPath(const std::string& filename, const std::string& location) { - DCHECK(!DexFileLoader::IsMultiDexLocation(filename.c_str())); + DCHECK(!DexFileLoader::IsMultiDexLocation(filename)); boot_class_path_.push_back(filename); if (!boot_class_path_locations_.empty()) { - DCHECK(!DexFileLoader::IsMultiDexLocation(location.c_str())); + DCHECK(!DexFileLoader::IsMultiDexLocation(location)); boot_class_path_locations_.push_back(location); } } @@ -3600,7 +3600,7 @@ void Runtime::AppendToBootClassPath( ScopedObjectAccess soa(Thread::Current()); for (const std::unique_ptr<const art::DexFile>& dex_file : dex_files) { // The first element must not be at a multi-dex location, while other elements must be. - DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str()), + DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation()), dex_file.get() == dex_files.begin()->get()); GetClassLinker()->AppendToBootClassPath(Thread::Current(), dex_file.get()); } @@ -3613,7 +3613,7 @@ void Runtime::AppendToBootClassPath(const std::string& filename, ScopedObjectAccess soa(Thread::Current()); for (const art::DexFile* dex_file : dex_files) { // The first element must not be at a multi-dex location, while other elements must be. - DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str()), + DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation()), dex_file == *dex_files.begin()); GetClassLinker()->AppendToBootClassPath(Thread::Current(), dex_file); } @@ -3628,7 +3628,7 @@ void Runtime::AppendToBootClassPath( ScopedObjectAccess soa(Thread::Current()); for (const auto& [dex_file, dex_cache] : dex_files_and_cache) { // The first element must not be at a multi-dex location, while other elements must be. - DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str()), + DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation()), dex_file == dex_files_and_cache.begin()->first); GetClassLinker()->AppendToBootClassPath(dex_file, dex_cache); } @@ -3642,7 +3642,7 @@ void Runtime::AddExtraBootDexFiles(const std::string& filename, if (kIsDebugBuild) { for (const std::unique_ptr<const art::DexFile>& dex_file : dex_files) { // The first element must not be at a multi-dex location, while other elements must be. - DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str()), + DCHECK_NE(DexFileLoader::IsMultiDexLocation(dex_file->GetLocation()), dex_file.get() == dex_files.begin()->get()); } } |