summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-06-12 09:30:37 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2024-06-14 10:14:50 +0000
commit2b4eb676348f122ab0a21e19d7a3c57bd9898c6c (patch)
tree281ceaa54365c8c38ca94ea484c831aeb1951bf8
parent9132d9056cc1d4eb342d1a2b0315fc1f054ca2f8 (diff)
Use C++20 `string{,_view}::{starts,ends}_with()`, part 2.
Replace uses of `android::base::{Starts,Ends}With()`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I80a0ca93f433464270989d248dd999e9366a1c17
-rw-r--r--artd/artd.cc3
-rw-r--r--artd/path_utils.cc4
-rw-r--r--cmdline/cmdline_types.h20
-rw-r--r--dex2oat/dex2oat.cc36
-rw-r--r--dexopt_chroot_setup/dexopt_chroot_setup.cc5
-rw-r--r--libartbase/base/file_utils.cc45
-rw-r--r--libartbase/base/file_utils.h6
-rw-r--r--libarttools/tools.cc5
-rw-r--r--libdexfile/dex/class_accessor-inl.h4
-rw-r--r--libdexfile/dex/class_accessor.h1
-rw-r--r--libdexfile/dex/fuzzer_corpus_test.cc10
-rw-r--r--libnativeloader/library_namespaces.cpp2
-rw-r--r--libnativeloader/public_libraries.cpp4
-rw-r--r--odrefresh/odrefresh.cc13
-rw-r--r--odrefresh/odrefresh_main.cc9
-rw-r--r--openjdkjvmti/ti_thread.cc7
-rw-r--r--runtime/class_linker_test.cc4
-rw-r--r--runtime/native_stack_dump.cc2
-rw-r--r--runtime/oat/elf_file.cc5
-rw-r--r--runtime/oat/oat_file_assistant.cc2
-rw-r--r--runtime/oat/oat_file_manager.cc2
-rw-r--r--runtime/verifier/method_verifier_test.cc2
-rw-r--r--test/dexpreopt/dexpreopt_test.cc6
-rw-r--r--tools/signal_dumper/signal_dumper.cc2
-rw-r--r--tools/veridex/class_filter.h8
-rw-r--r--tools/veridex/hidden_api_finder.cc2
26 files changed, 101 insertions, 108 deletions
diff --git a/artd/artd.cc b/artd/artd.cc
index 094962e027..1173dfd284 100644
--- a/artd/artd.cc
+++ b/artd/artd.cc
@@ -118,7 +118,6 @@ using ::android::base::ParseInt;
using ::android::base::ReadFileToString;
using ::android::base::Result;
using ::android::base::Split;
-using ::android::base::StartsWith;
using ::android::base::Tokenize;
using ::android::base::Trim;
using ::android::base::WriteStringToFd;
@@ -1939,7 +1938,7 @@ Result<BuildSystemProperties> BuildSystemProperties::Create(const std::string& f
std::unordered_map<std::string, std::string> system_properties;
for (const std::string& raw_line : Split(content, "\n")) {
std::string line = Trim(raw_line);
- if (line.empty() || StartsWith(line, '#')) {
+ if (line.empty() || line.starts_with('#')) {
continue;
}
size_t pos = line.find('=');
diff --git a/artd/path_utils.cc b/artd/path_utils.cc
index 5c6ad9dc02..8348a7605d 100644
--- a/artd/path_utils.cc
+++ b/artd/path_utils.cc
@@ -23,7 +23,6 @@
#include "aidl/com/android/server/art/BnArtd.h"
#include "android-base/errors.h"
#include "android-base/result.h"
-#include "android-base/strings.h"
#include "arch/instruction_set.h"
#include "base/file_utils.h"
#include "base/macros.h"
@@ -45,7 +44,6 @@ using ::aidl::com::android::server::art::OutputProfile;
using ::aidl::com::android::server::art::ProfilePath;
using ::aidl::com::android::server::art::RuntimeArtifactsPath;
using ::aidl::com::android::server::art::VdexPath;
-using ::android::base::EndsWith;
using ::android::base::Error;
using ::android::base::Result;
using ::art::service::ValidateDexPath;
@@ -335,7 +333,7 @@ bool PreRebootFlag(const VdexPath& vdex_path) {
}
bool IsPreRebootStagedFile(std::string_view filename) {
- return EndsWith(filename, kPreRebootSuffix);
+ return filename.ends_with(kPreRebootSuffix);
}
void TestOnlySetListRootDir(std::string_view root_dir) { gListRootDir = root_dir; }
diff --git a/cmdline/cmdline_types.h b/cmdline/cmdline_types.h
index 34c1b0fc97..4a33fb8b55 100644
--- a/cmdline/cmdline_types.h
+++ b/cmdline/cmdline_types.h
@@ -813,58 +813,58 @@ struct CmdlineType<ProfileSaverOptions> : CmdlineTypeParser<ProfileSaverOptions>
// The rest of these options are always the wildcard from '-Xps-*'
std::string suffix = RemovePrefix(option);
- if (android::base::StartsWith(option, "min-save-period-ms:")) {
+ if (option.starts_with("min-save-period-ms:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::min_save_period_ms_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "min-first-save-ms:")) {
+ if (option.starts_with("min-first-save-ms:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::min_first_save_ms_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "save-resolved-classes-delay-ms:")) {
+ if (option.starts_with("save-resolved-classes-delay-ms:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::save_resolved_classes_delay_ms_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "hot-startup-method-samples:")) {
+ if (option.starts_with("hot-startup-method-samples:")) {
LOG(WARNING) << "-Xps-hot-startup-method-samples option is deprecated";
return Result::SuccessNoValue();
}
- if (android::base::StartsWith(option, "min-methods-to-save:")) {
+ if (option.starts_with("min-methods-to-save:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::min_methods_to_save_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "min-classes-to-save:")) {
+ if (option.starts_with("min-classes-to-save:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::min_classes_to_save_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "min-notification-before-wake:")) {
+ if (option.starts_with("min-notification-before-wake:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::min_notification_before_wake_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "max-notification-before-wake:")) {
+ if (option.starts_with("max-notification-before-wake:")) {
CmdlineType<unsigned int> type_parser;
return ParseInto(existing,
&ProfileSaverOptions::max_notification_before_wake_,
type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "inline-cache-threshold:")) {
+ if (option.starts_with("inline-cache-threshold:")) {
CmdlineType<uint16_t> type_parser;
return ParseInto(
existing, &ProfileSaverOptions::inline_cache_threshold_, type_parser.Parse(suffix));
}
- if (android::base::StartsWith(option, "profile-path:")) {
+ if (option.starts_with("profile-path:")) {
existing.profile_path_ = suffix;
return Result::SuccessNoValue();
}
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 45e6ae1052..31a83bd198 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -153,34 +153,36 @@ static std::string StrippedCommandLine() {
bool saw_zip_fd = false;
bool saw_compiler_filter = false;
for (int i = 0; i < original_argc; ++i) {
- if (android::base::StartsWith(original_argv[i], "--zip-fd=")) {
+ std::string_view arg(original_argv[i]);
+ if (arg.starts_with("--zip-fd=")) {
saw_zip_fd = true;
}
- if (android::base::StartsWith(original_argv[i], "--compiler-filter=")) {
+ if (arg.starts_with("--compiler-filter=")) {
saw_compiler_filter = true;
}
}
// Now filter out things.
for (int i = 0; i < original_argc; ++i) {
+ std::string_view arg(original_argv[i]);
// All runtime-arg parameters are dropped.
- if (strcmp(original_argv[i], "--runtime-arg") == 0) {
+ if (arg == "--runtime-arg") {
i++; // Drop the next part, too.
continue;
}
// Any instruction-setXXX is dropped.
- if (android::base::StartsWith(original_argv[i], "--instruction-set")) {
+ if (arg.starts_with("--instruction-set")) {
continue;
}
// The boot image is dropped.
- if (android::base::StartsWith(original_argv[i], "--boot-image=")) {
+ if (arg.starts_with("--boot-image=")) {
continue;
}
// The image format is dropped.
- if (android::base::StartsWith(original_argv[i], "--image-format=")) {
+ if (arg.starts_with("--image-format=")) {
continue;
}
@@ -189,16 +191,16 @@ static std::string StrippedCommandLine() {
// However, we prefer to drop this when we saw --zip-fd.
if (saw_zip_fd) {
// Drop anything --zip-X, --dex-X, --oat-X, --swap-X, or --app-image-X
- if (android::base::StartsWith(original_argv[i], "--zip-") ||
- android::base::StartsWith(original_argv[i], "--dex-") ||
- android::base::StartsWith(original_argv[i], "--oat-") ||
- android::base::StartsWith(original_argv[i], "--swap-") ||
- android::base::StartsWith(original_argv[i], "--app-image-")) {
+ if (arg.starts_with("--zip-") ||
+ arg.starts_with("--dex-") ||
+ arg.starts_with("--oat-") ||
+ arg.starts_with("--swap-") ||
+ arg.starts_with("--app-image-")) {
continue;
}
}
- command.push_back(original_argv[i]);
+ command.push_back(std::string(arg));
}
if (!saw_compiler_filter) {
@@ -725,8 +727,8 @@ class Dex2Oat final {
if (!IsBootImage() && boot_image_filename_.empty()) {
DCHECK(!IsBootImageExtension());
- if (std::any_of(runtime_args_.begin(), runtime_args_.end(), [](const char* arg) {
- return android::base::StartsWith(arg, "-Xbootclasspath:");
+ if (std::any_of(runtime_args_.begin(), runtime_args_.end(), [](std::string_view arg) {
+ return arg.starts_with("-Xbootclasspath:");
})) {
LOG(WARNING) << "--boot-image is not specified while -Xbootclasspath is specified. Running "
"dex2oat in imageless mode";
@@ -1615,7 +1617,7 @@ class Dex2Oat final {
TimingLogger::ScopedTiming t3("Loading image checksum", timings_);
std::string full_bcp = android::base::Join(runtime->GetBootClassPathLocations(), ':');
std::string extension_part = ":" + android::base::Join(dex_locations_, ':');
- if (!android::base::EndsWith(full_bcp, extension_part)) {
+ if (!full_bcp.ends_with(extension_part)) {
LOG(ERROR) << "Full boot class path does not end with extension parts, full: " << full_bcp
<< ", extension: " << extension_part.substr(1u);
return dex2oat::ReturnCode::kOther;
@@ -1873,7 +1875,7 @@ class Dex2Oat final {
for (const std::string& filter : no_inline_filters) {
// Use dex_file->GetLocation() rather than dex_file->GetBaseLocation(). This
// allows tests to specify <test-dexfile>!classes2.dex if needed but if the
- // base location passes the StartsWith() test, so do all extra locations.
+ // base location passes the `starts_with()` test, so do all extra locations.
std::string dex_location = dex_file->GetLocation();
if (filter.find('/') == std::string::npos) {
// The filter does not contain the path. Remove the path from dex_location as well.
@@ -1883,7 +1885,7 @@ class Dex2Oat final {
}
}
- if (android::base::StartsWith(dex_location, filter)) {
+ if (dex_location.starts_with(filter)) {
VLOG(compiler) << "Disabling inlining from " << dex_file->GetLocation();
no_inline_from_dex_files.push_back(dex_file);
break;
diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.cc b/dexopt_chroot_setup/dexopt_chroot_setup.cc
index d98f883df9..937cd3028b 100644
--- a/dexopt_chroot_setup/dexopt_chroot_setup.cc
+++ b/dexopt_chroot_setup/dexopt_chroot_setup.cc
@@ -58,7 +58,6 @@ namespace dexopt_chroot_setup {
namespace {
using ::android::base::ConsumePrefix;
-using ::android::base::EndsWith;
using ::android::base::Error;
using ::android::base::Join;
using ::android::base::NoDestructor;
@@ -210,7 +209,7 @@ Result<void> BindMount(const std::string& source, const std::string& target) {
}
Result<void> BindMountRecursive(const std::string& source, const std::string& target) {
- CHECK(!EndsWith(source, '/'));
+ CHECK(!source.ends_with('/'));
OR_RETURN(BindMount(source, target));
// Mount and make slave one by one. Do not use MS_REC because we don't want to mount a child if
@@ -222,7 +221,7 @@ Result<void> BindMountRecursive(const std::string& source, const std::string& ta
// The list is in mount order.
std::vector<FstabEntry> entries = OR_RETURN(GetProcMountsDescendantsOfPath(source));
for (const FstabEntry& entry : entries) {
- CHECK(!EndsWith(entry.mount_point, '/'));
+ CHECK(!entry.mount_point.ends_with('/'));
std::string_view sub_dir = entry.mount_point;
CHECK(ConsumePrefix(&sub_dir, source));
if (sub_dir.empty()) {
diff --git a/libartbase/base/file_utils.cc b/libartbase/base/file_utils.cc
index 0573e9037b..1be8327b13 100644
--- a/libartbase/base/file_utils.cc
+++ b/libartbase/base/file_utils.cc
@@ -622,27 +622,27 @@ void GetDalvikCache(const char* subdir,
// Returns a path formed by encoding the dex location into the filename. The path returned will be
// rooted at `cache_location`.
-static bool GetLocationEncodedFilename(const char* location,
- const char* cache_location,
+static bool GetLocationEncodedFilename(std::string_view location,
+ std::string_view cache_location,
std::string* filename,
std::string* error_msg) {
- if (location[0] != '/') {
- *error_msg = StringPrintf("Expected path in location to be absolute: %s", location);
+ if (!location.starts_with('/')) {
+ *error_msg = "Expected path in location to be absolute: " + std::string(location);
return false;
}
- std::string cache_file(&location[1]); // skip leading slash
- if (!android::base::EndsWith(location, ".dex") && !android::base::EndsWith(location, ".art") &&
- !android::base::EndsWith(location, ".oat")) {
- cache_file += "/";
- cache_file += kClassesDex;
+ *filename = cache_location;
+ *filename += location; // Including the leading slash.
+ size_t replace_start = cache_location.length() + /* skip the leading slash from `location` */ 1u;
+ std::replace(filename->begin() + replace_start, filename->end(), '/', '@');
+ if (!location.ends_with(".dex") && !location.ends_with(".art") && !location.ends_with(".oat")) {
+ *filename += "@";
+ *filename += kClassesDex;
}
- std::replace(cache_file.begin(), cache_file.end(), '/', '@');
- *filename = StringPrintf("%s/%s", cache_location, cache_file.c_str());
return true;
}
-bool GetDalvikCacheFilename(const char* location,
- const char* cache_location,
+bool GetDalvikCacheFilename(std::string_view location,
+ std::string_view cache_location,
std::string* filename,
std::string* error_msg) {
return GetLocationEncodedFilename(location, cache_location, filename, error_msg);
@@ -669,8 +669,8 @@ static std::string GetApexDataDalvikCacheFilename(std::string_view dex_location,
// Result:
// "/data/misc/apexdata/com.android.art/dalvik-cache/arm/system@framework@xyz.jar@classes.odex"
std::string result, unused_error_msg;
- GetDalvikCacheFilename(std::string{dex_location}.c_str(),
- apex_data_dalvik_cache.c_str(),
+ GetDalvikCacheFilename(dex_location,
+ apex_data_dalvik_cache,
&result,
&unused_error_msg);
return ReplaceFileExtension(result, file_extension);
@@ -724,8 +724,7 @@ std::string GetSystemOdexFilenameForApex(std::string_view location, InstructionS
DCHECK(LocationIsOnApex(location));
std::string dir = GetAndroidRoot() + "/framework/oat/" + GetInstructionSetString(isa);
std::string result, error_msg;
- bool ret =
- GetLocationEncodedFilename(std::string{location}.c_str(), dir.c_str(), &result, &error_msg);
+ bool ret = GetLocationEncodedFilename(location, dir, &result, &error_msg);
// This should never fail. The function fails only if the location is not absolute, and a location
// on /apex is always absolute.
DCHECK(ret) << error_msg;
@@ -764,7 +763,7 @@ std::string ReplaceFileExtension(std::string_view filename, std::string_view new
bool LocationIsOnArtApexData(std::string_view location) {
const std::string art_apex_data = GetArtApexData();
- return android::base::StartsWith(location, art_apex_data);
+ return location.starts_with(art_apex_data);
}
bool LocationIsOnArtModule(std::string_view full_path) {
@@ -773,7 +772,7 @@ bool LocationIsOnArtModule(std::string_view full_path) {
if (module_path.empty()) {
return false;
}
- return android::base::StartsWith(full_path, module_path);
+ return full_path.starts_with(module_path);
}
static bool StartsWithSlash(const char* str) {
@@ -821,7 +820,7 @@ static bool IsLocationOn(std::string_view full_path,
path_prefix.append(subdir);
}
- return android::base::StartsWith(full_path, path_prefix);
+ return full_path.starts_with(path_prefix);
}
bool LocationIsOnSystemFramework(std::string_view full_path) {
@@ -853,11 +852,11 @@ bool LocationIsOnI18nModule(std::string_view full_path) {
}
bool LocationIsOnApex(std::string_view full_path) {
- return android::base::StartsWith(full_path, kApexDefaultPath);
+ return full_path.starts_with(kApexDefaultPath);
}
std::string_view ApexNameFromLocation(std::string_view full_path) {
- if (!android::base::StartsWith(full_path, kApexDefaultPath)) {
+ if (!full_path.starts_with(kApexDefaultPath)) {
return {};
}
size_t start = strlen(kApexDefaultPath);
@@ -874,7 +873,7 @@ bool LocationIsOnSystem(const std::string& location) {
LOG(FATAL) << "LocationIsOnSystem is unsupported on Windows.";
return false;
#else
- return android::base::StartsWith(location, GetAndroidRoot());
+ return location.starts_with(GetAndroidRoot());
#endif
}
diff --git a/libartbase/base/file_utils.h b/libartbase/base/file_utils.h
index 8222a8a1d4..205cc6115d 100644
--- a/libartbase/base/file_utils.h
+++ b/libartbase/base/file_utils.h
@@ -127,8 +127,10 @@ void GetDalvikCache(const char* subdir, bool create_if_absent, std::string* dalv
// Returns the absolute dalvik-cache path for a DexFile or OatFile. The path returned will be
// rooted at `cache_location`.
-bool GetDalvikCacheFilename(const char* location, const char* cache_location,
- std::string* filename, std::string* error_msg);
+bool GetDalvikCacheFilename(std::string_view location,
+ std::string_view cache_location,
+ std::string* filename,
+ std::string* error_msg);
// Returns the absolute dalvik-cache path. The path may include the instruction set sub-directory
// if specified.
diff --git a/libarttools/tools.cc b/libarttools/tools.cc
index 0dadfde564..1a4e54ed07 100644
--- a/libarttools/tools.cc
+++ b/libarttools/tools.cc
@@ -59,7 +59,6 @@ using ::android::base::function_ref;
using ::android::base::ReadFileToString;
using ::android::base::Readlink;
using ::android::base::Result;
-using ::android::base::StartsWith;
using ::android::base::unique_fd;
using ::android::fs_mgr::Fstab;
using ::android::fs_mgr::FstabEntry;
@@ -181,7 +180,7 @@ bool PathStartsWith(std::string_view path, std::string_view prefix) {
CHECK(!prefix.empty() && !path.empty() && prefix[0] == '/' && path[0] == '/')
<< ART_FORMAT("path={}, prefix={}", path, prefix);
ConsumeSuffix(&prefix, "/");
- return StartsWith(path, prefix) &&
+ return path.starts_with(prefix) &&
(path.length() == prefix.length() || path[prefix.length()] == '/');
}
@@ -197,7 +196,7 @@ static Result<std::vector<FstabEntry>> GetProcMountsMatches(
// field, according to fstab(5). In addition, ignore any other entries whose mount points are
// not absolute paths, just in case there are other fs types that also have an meaningless mount
// point.
- if (entry.fs_type == "swap" || !StartsWith(entry.mount_point, '/')) {
+ if (entry.fs_type == "swap" || !entry.mount_point.starts_with('/')) {
continue;
}
if (predicate(entry.mount_point)) {
diff --git a/libdexfile/dex/class_accessor-inl.h b/libdexfile/dex/class_accessor-inl.h
index 4239da97a8..5979f86e8d 100644
--- a/libdexfile/dex/class_accessor-inl.h
+++ b/libdexfile/dex/class_accessor-inl.h
@@ -154,6 +154,10 @@ inline const char* ClassAccessor::GetDescriptor() const {
return dex_file_.GetTypeDescriptor(GetClassIdx());
}
+inline std::string_view ClassAccessor::GetDescriptorView() const {
+ return dex_file_.GetTypeDescriptorView(GetClassIdx());
+}
+
inline const dex::CodeItem* ClassAccessor::Method::GetCodeItem() const {
return dex_file_.GetCodeItem(code_off_);
}
diff --git a/libdexfile/dex/class_accessor.h b/libdexfile/dex/class_accessor.h
index 401195c6fe..df34e0eccb 100644
--- a/libdexfile/dex/class_accessor.h
+++ b/libdexfile/dex/class_accessor.h
@@ -351,6 +351,7 @@ class ClassAccessor {
}
const char* GetDescriptor() const;
+ std::string_view GetDescriptorView() const;
dex::TypeIndex GetClassIdx() const;
diff --git a/libdexfile/dex/fuzzer_corpus_test.cc b/libdexfile/dex/fuzzer_corpus_test.cc
index 15aa6dd657..24057e536d 100644
--- a/libdexfile/dex/fuzzer_corpus_test.cc
+++ b/libdexfile/dex/fuzzer_corpus_test.cc
@@ -65,14 +65,6 @@ class ZipArchiveHandleScope {
std::unique_ptr<ZipArchiveHandle> handle_;
};
-// Returns true if `str` ends with `suffix`.
-inline bool EndsWith(std::string const& str, std::string const& suffix) {
- if (suffix.size() > str.size()) {
- return false;
- }
- return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin());
-}
-
// Tests that we can verify dex files without crashing.
TEST_F(FuzzerCorpusTest, VerifyCorpusDexFiles) {
// These dex files are expected to pass verification. The others are regressions tests.
@@ -101,7 +93,7 @@ TEST_F(FuzzerCorpusTest, VerifyCorpusDexFiles) {
std::string name;
std::vector<char> data;
while ((error = Next(cookie, &entry, &name)) >= 0) {
- if (!EndsWith(name, ".dex")) {
+ if (!name.ends_with(".dex")) {
// Skip non-DEX files.
LOG(WARNING) << "Found a non-dex file: " << name;
continue;
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index 7b18b15dd0..e0f3d6af8c 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -483,7 +483,7 @@ std::optional<std::string> FindApexNamespaceName(const std::string& location) {
// /apex/modulename/...
//
// And we extract from it 'modulename', and then apply mangling rule to get namespace name for it.
- if (android::base::StartsWith(location, kApexPath)) {
+ if (location.starts_with(kApexPath)) {
size_t start_index = strlen(kApexPath);
size_t slash_index = location.find_first_of('/', start_index);
LOG_ALWAYS_FATAL_IF((slash_index == std::string::npos),
diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp
index 53fcd2f35b..3fecd59cf7 100644
--- a/libnativeloader/public_libraries.cpp
+++ b/libnativeloader/public_libraries.cpp
@@ -126,8 +126,8 @@ void ReadExtensionLibraries(const char* dirname, std::vector<std::string>* sonam
Result<std::vector<std::string>> ret = ReadConfig(
config_file_path, [&company_name](const struct ConfigEntry& entry) -> Result<bool> {
- if (android::base::StartsWith(entry.soname, "lib") &&
- android::base::EndsWith(entry.soname, "." + company_name + ".so")) {
+ if (entry.soname.starts_with("lib") &&
+ entry.soname.ends_with("." + company_name + ".so")) {
return true;
} else {
return Errorf(
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 9a3f9f67cb..6a09a88a4e 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -105,7 +105,6 @@ using ::android::base::Result;
using ::android::base::ScopeGuard;
using ::android::base::SetProperty;
using ::android::base::Split;
-using ::android::base::StartsWith;
using ::android::base::StringPrintf;
using ::android::base::Timer;
using ::android::modules::sdklevel::IsAtLeastU;
@@ -253,9 +252,9 @@ std::vector<art_apex::ModuleInfo> GenerateModuleInfoList(
// Returns a rewritten path based on environment variables for interesting paths.
std::string RewriteParentDirectoryIfNeeded(const std::string& path) {
- if (StartsWith(path, "/system/")) {
+ if (path.starts_with("/system/")) {
return GetAndroidRoot() + path.substr(7);
- } else if (StartsWith(path, "/system_ext/")) {
+ } else if (path.starts_with("/system_ext/")) {
return GetSystemExtRoot() + path.substr(11);
} else {
return path;
@@ -494,7 +493,7 @@ Result<void> AddBootClasspathFds(/*inout*/ CmdlineBuilder& args,
// Special treatment for Compilation OS. JARs in staged APEX may not be visible to Android, and
// may only be visible in the VM where the staged APEX is mounted. On the contrary, JARs in
// /system is not available by path in the VM, and can only made available via (remote) FDs.
- if (StartsWith(jar, "/apex/")) {
+ if (jar.starts_with("/apex/")) {
bcp_fds.emplace_back("-1");
} else {
std::string actual_path = RewriteParentDirectoryIfNeeded(jar);
@@ -892,7 +891,7 @@ std::vector<std::string> OnDeviceRefresh::GetArtBcpJars() const {
std::string art_root = GetArtRoot() + "/";
std::vector<std::string> art_bcp_jars;
for (const std::string& jar : dex2oat_boot_classpath_jars_) {
- if (StartsWith(jar, art_root)) {
+ if (jar.starts_with(art_root)) {
art_bcp_jars.push_back(jar);
}
}
@@ -904,7 +903,7 @@ std::vector<std::string> OnDeviceRefresh::GetFrameworkBcpJars() const {
std::string art_root = GetArtRoot() + "/";
std::vector<std::string> framework_bcp_jars;
for (const std::string& jar : dex2oat_boot_classpath_jars_) {
- if (!StartsWith(jar, art_root)) {
+ if (!jar.starts_with(art_root)) {
framework_bcp_jars.push_back(jar);
}
}
@@ -1093,7 +1092,7 @@ WARN_UNUSED bool OnDeviceRefresh::CheckSystemPropertiesAreDefault() const {
// `cache-info.xml` exists, we call `CheckSystemPropertiesHaveNotChanged` instead.
DCHECK(std::none_of(std::begin(kCheckedSystemPropertyPrefixes),
std::end(kCheckedSystemPropertyPrefixes),
- [](const char* prefix) { return StartsWith(prefix, "persist."); }));
+ [](std::string_view prefix) { return prefix.starts_with("persist."); }));
const OdrSystemProperties& system_properties = config_.GetSystemProperties();
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 144a9e97ae..2d3009e25c 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -41,7 +41,6 @@ namespace {
using ::android::base::GetProperty;
using ::android::base::ParseBool;
using ::android::base::ParseBoolResult;
-using ::android::base::StartsWith;
using ::art::odrefresh::CompilationOptions;
using ::art::odrefresh::ExitCode;
using ::art::odrefresh::kCheckedSystemPropertyPrefixes;
@@ -117,7 +116,7 @@ std::string GetEnvironmentVariableOrDefault(const char* name, std::string defaul
}
bool ArgumentMatches(std::string_view argument, std::string_view prefix, std::string* value) {
- if (android::base::StartsWith(argument, prefix)) {
+ if (argument.starts_with(prefix)) {
*value = std::string(argument.substr(prefix.size()));
return true;
}
@@ -202,13 +201,13 @@ int InitializeConfig(int argc, char** argv, OdrConfig* config) {
}
void GetSystemProperties(std::unordered_map<std::string, std::string>* system_properties) {
- SystemPropertyForeach([&](const char* name, const char* value) {
+ SystemPropertyForeach([&](std::string_view name, const char* value) {
if (strlen(value) == 0) {
return;
}
for (const char* prefix : kCheckedSystemPropertyPrefixes) {
- if (StartsWith(name, prefix)) {
- (*system_properties)[name] = value;
+ if (name.starts_with(prefix)) {
+ (*system_properties)[std::string(name)] = value;
}
}
});
diff --git a/openjdkjvmti/ti_thread.cc b/openjdkjvmti/ti_thread.cc
index 6b3cf30aee..9c71d4e3cc 100644
--- a/openjdkjvmti/ti_thread.cc
+++ b/openjdkjvmti/ti_thread.cc
@@ -32,7 +32,6 @@
#include "ti_thread.h"
#include <android-base/logging.h>
-#include <android-base/strings.h>
#include "art_field-inl.h"
#include "art_jvmti.h"
@@ -130,9 +129,9 @@ struct ThreadCallback : public art::ThreadLifecycleCallback {
self->GetThreadName(name);
if (name != "JDWP" && name != "Signal Catcher" && name != "perfetto_hprof_listener" &&
name != art::metrics::MetricsReporter::kBackgroundThreadName &&
- !android::base::StartsWith(name, "Jit thread pool") &&
- !android::base::StartsWith(name, "Heap thread pool worker thread") &&
- !android::base::StartsWith(name, "Runtime worker thread")) {
+ !name.starts_with("Jit thread pool") &&
+ !name.starts_with("Heap thread pool worker thread") &&
+ !name.starts_with("Runtime worker thread")) {
LOG(FATAL) << "Unexpected thread before start: " << name << " id: "
<< self->GetThreadId();
}
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index df669169e0..932341d895 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -896,12 +896,12 @@ TEST_F(ClassLinkerTest, GetDexFiles) {
jobject jclass_loader = LoadDex("Nested");
std::vector<const DexFile*> dex_files(GetDexFiles(jclass_loader));
ASSERT_EQ(dex_files.size(), 1U);
- EXPECT_TRUE(android::base::EndsWith(dex_files[0]->GetLocation(), "Nested.jar"));
+ EXPECT_TRUE(dex_files[0]->GetLocation().ends_with("Nested.jar"));
jobject jclass_loader2 = LoadDex("MultiDex");
std::vector<const DexFile*> dex_files2(GetDexFiles(jclass_loader2));
ASSERT_EQ(dex_files2.size(), 2U);
- EXPECT_TRUE(android::base::EndsWith(dex_files2[0]->GetLocation(), "MultiDex.jar"));
+ EXPECT_TRUE(dex_files2[0]->GetLocation().ends_with("MultiDex.jar"));
}
TEST_F(ClassLinkerTest, FindClassNested) {
diff --git a/runtime/native_stack_dump.cc b/runtime/native_stack_dump.cc
index ad09762972..5a6cee0630 100644
--- a/runtime/native_stack_dump.cc
+++ b/runtime/native_stack_dump.cc
@@ -236,7 +236,7 @@ static void Addr2line(const std::string& map_src,
std::unique_ptr<Addr2linePipe>* pipe /* inout */) {
std::array<const char*, 3> kIgnoreSuffixes{ ".dex", ".jar", ".vdex" };
for (const char* ignore_suffix : kIgnoreSuffixes) {
- if (android::base::EndsWith(map_src, ignore_suffix)) {
+ if (map_src.ends_with(ignore_suffix)) {
// Ignore file names that do not have map information addr2line can consume. e.g. vdex
// files are special frames injected for the interpreter so they don't have any line
// number information available.
diff --git a/runtime/oat/elf_file.cc b/runtime/oat/elf_file.cc
index 91af410471..c66cba1dd0 100644
--- a/runtime/oat/elf_file.cc
+++ b/runtime/oat/elf_file.cc
@@ -1434,9 +1434,8 @@ bool ElfFileImpl<ElfTypes>::Strip(File* file, std::string* error_msg) {
section_headers_original_indexes.push_back(0);
continue;
}
- if (android::base::StartsWith(name, ".debug")
- || (strcmp(name, ".strtab") == 0)
- || (strcmp(name, ".symtab") == 0)) {
+ std::string_view name_sv(name);
+ if (name_sv.starts_with(".debug") || (name_sv == ".strtab") || (name_sv == ".symtab")) {
continue;
}
section_headers.push_back(*sh);
diff --git a/runtime/oat/oat_file_assistant.cc b/runtime/oat/oat_file_assistant.cc
index 8fcf1c8f57..782b7b3316 100644
--- a/runtime/oat/oat_file_assistant.cc
+++ b/runtime/oat/oat_file_assistant.cc
@@ -701,7 +701,7 @@ bool OatFileAssistant::DexLocationToOatFilename(const std::string& location,
// TODO: The oat file assistant should be the definitive place for
// determining the oat file name from the dex location, not
// GetDalvikCacheFilename.
- return GetDalvikCacheFilename(location.c_str(), dalvik_cache.c_str(), oat_filename, error_msg);
+ return GetDalvikCacheFilename(location, dalvik_cache, oat_filename, error_msg);
}
bool OatFileAssistant::GetRequiredDexChecksum(std::optional<uint32_t>* checksum,
diff --git a/runtime/oat/oat_file_manager.cc b/runtime/oat/oat_file_manager.cc
index fea361b8ee..c32125cf75 100644
--- a/runtime/oat/oat_file_manager.cc
+++ b/runtime/oat/oat_file_manager.cc
@@ -829,7 +829,7 @@ void OatFileManager::RunBackgroundVerification(const std::vector<const DexFile*>
std::string dex_location = dex_files[0]->GetLocation();
const std::string& data_dir = Runtime::Current()->GetProcessDataDirectory();
- if (!android::base::StartsWith(dex_location, data_dir)) {
+ if (!dex_location.starts_with(data_dir)) {
// For now, we only run background verification for secondary dex files.
// Running it for primary or split APKs could have some undesirable
// side-effects, like overloading the device on app startup.
diff --git a/runtime/verifier/method_verifier_test.cc b/runtime/verifier/method_verifier_test.cc
index 1c6ed7c9b0..acfc7b2b19 100644
--- a/runtime/verifier/method_verifier_test.cc
+++ b/runtime/verifier/method_verifier_test.cc
@@ -65,7 +65,7 @@ class MethodVerifierTest : public CommonRuntimeTest {
/* api_level= */ 0u,
&error_msg);
- if (android::base::StartsWith(descriptor, "Ljava/lang/invoke")) {
+ if (descriptor.starts_with("Ljava/lang/invoke")) {
ASSERT_TRUE(failure == FailureKind::kSoftFailure ||
failure == FailureKind::kNoFailure) << error_msg;
diff --git a/test/dexpreopt/dexpreopt_test.cc b/test/dexpreopt/dexpreopt_test.cc
index c5d34007ab..aeb46ae9f4 100644
--- a/test/dexpreopt/dexpreopt_test.cc
+++ b/test/dexpreopt/dexpreopt_test.cc
@@ -113,8 +113,8 @@ android::base::Result<std::vector<std::string>> GetZygoteExpectedArtifacts(Instr
const std::string& jar = jars[i];
std::string basename =
i == 0 ? "boot.oat" : "boot-" + ReplaceFileExtension(android::base::Basename(jar), "oat");
- std::string dir = android::base::StartsWith(jar, art_root) ? GetPrebuiltPrimaryBootImageDir() :
- android_root + "/framework";
+ std::string dir = jar.starts_with(art_root) ? GetPrebuiltPrimaryBootImageDir()
+ : android_root + "/framework";
std::string oat_file = android::base::StringPrintf(
"%s/%s/%s", dir.c_str(), GetInstructionSetString(isa), basename.c_str());
@@ -174,7 +174,7 @@ android::base::Result<std::vector<std::string>> GetMappedFiles(pid_t pid,
}
std::vector<std::string> files;
for (const android::procinfo::MapInfo& map : maps) {
- if ((map.flags & flags) && android::base::EndsWith(map.name, extension)) {
+ if ((map.flags & flags) && map.name.ends_with(extension)) {
files.push_back(map.name);
}
}
diff --git a/tools/signal_dumper/signal_dumper.cc b/tools/signal_dumper/signal_dumper.cc
index 019b9897e8..7082f0a5a5 100644
--- a/tools/signal_dumper/signal_dumper.cc
+++ b/tools/signal_dumper/signal_dumper.cc
@@ -280,7 +280,7 @@ void Addr2line(const std::string& addr2line,
std::unique_ptr<Addr2linePipe>* pipe /* inout */) {
DCHECK(pipe != nullptr);
- if (map_src == "[vdso]" || android::base::EndsWith(map_src, ".vdex")) {
+ if (map_src == "[vdso]" || map_src.ends_with(".vdex")) {
// addr2line will not work on the vdso.
// vdex files are special frames injected for the interpreter
// so they don't have any line number information available.
diff --git a/tools/veridex/class_filter.h b/tools/veridex/class_filter.h
index aa74d53732..cb4951efd2 100644
--- a/tools/veridex/class_filter.h
+++ b/tools/veridex/class_filter.h
@@ -17,7 +17,9 @@
#ifndef ART_TOOLS_VERIDEX_CLASS_FILTER_H_
#define ART_TOOLS_VERIDEX_CLASS_FILTER_H_
-#include <android-base/strings.h>
+#include <vector>
+#include <string>
+#include <string_view>
namespace art {
@@ -25,13 +27,13 @@ class ClassFilter {
public:
explicit ClassFilter(const std::vector<std::string>& prefixes) : prefixes_(prefixes) {}
- bool Matches(const char* class_descriptor) const {
+ bool Matches(std::string_view class_descriptor) const {
if (prefixes_.empty()) {
return true;
}
for (const std::string& filter : prefixes_) {
- if (android::base::StartsWith(class_descriptor, filter)) {
+ if (class_descriptor.starts_with(filter)) {
return true;
}
}
diff --git a/tools/veridex/hidden_api_finder.cc b/tools/veridex/hidden_api_finder.cc
index 9455b0f10b..f0c520f3ee 100644
--- a/tools/veridex/hidden_api_finder.cc
+++ b/tools/veridex/hidden_api_finder.cc
@@ -59,7 +59,7 @@ void HiddenApiFinder::CollectAccesses(VeridexResolver* resolver,
// Note: we collect strings constants only referenced in code items as the string table
// contains other kind of strings (eg types).
for (ClassAccessor accessor : dex_file.GetClasses()) {
- if (class_filter.Matches(accessor.GetDescriptor())) {
+ if (class_filter.Matches(accessor.GetDescriptorView())) {
for (const ClassAccessor::Method& method : accessor.GetMethods()) {
CodeItemInstructionAccessor codes = method.GetInstructions();
const uint32_t max_pc = codes.InsnsSizeInCodeUnits();