summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-06-12 07:46:46 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2024-06-13 14:20:24 +0000
commit20f803bad38828a3e1d7754d7123971b7b42ddba (patch)
tree71408134bec25cfcc24e2d68af9b414a93ec4110
parent155920b599580c86d341181cd544d14bbca32e76 (diff)
Use C++20 `string{,_view}::{starts,ends}_with()`, part 1.
Remove the header file `string_view_cpp20.h` and update all source files that previously used this header file. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Iafcdfc838a97deed7fb3a37cc8afe1f7ee78306b
-rw-r--r--cmdline/cmdline.h17
-rw-r--r--compiler/driver/compiler_options.cc1
-rw-r--r--compiler/jit/jit_compiler.cc5
-rw-r--r--compiler/utils/riscv64/assembler_riscv64_test.cc2
-rw-r--r--dex2oat/dex2oat_image_test.cc5
-rw-r--r--dex2oat/dex2oat_test.cc3
-rw-r--r--dex2oat/driver/compiler_driver.cc5
-rw-r--r--dexoptanalyzer/dexoptanalyzer.cc23
-rw-r--r--imgdiag/imgdiag.cc9
-rw-r--r--imgdiag/page_info.cc4
-rw-r--r--libartbase/base/common_art_test.cc5
-rw-r--r--libartbase/base/string_view_cpp20.h45
-rw-r--r--libdexfile/dex/signature.cc8
-rw-r--r--oatdump/oatdump.cc37
-rw-r--r--odrefresh/odr_artifacts_test.cc5
-rw-r--r--odrefresh/odr_metrics.cc3
-rw-r--r--profman/profman.cc90
-rw-r--r--runtime/class_linker.cc1
-rw-r--r--runtime/class_loader_context_test.cc7
-rw-r--r--runtime/compat_framework.h1
-rw-r--r--runtime/gc/space/image_space.cc15
-rw-r--r--runtime/hidden_api_test.cc2
-rw-r--r--runtime/jni/java_vm_ext.cc3
-rw-r--r--runtime/oat/oat_file.cc5
-rw-r--r--runtime/oat/oat_file_assistant.cc15
-rw-r--r--runtime/runtime.h1
-rw-r--r--tools/art_verifier/art_verifier.cc6
-rw-r--r--tools/hiddenapi/hiddenapi.cc23
28 files changed, 139 insertions, 207 deletions
diff --git a/cmdline/cmdline.h b/cmdline/cmdline.h
index 958f80d057..39fcaebd63 100644
--- a/cmdline/cmdline.h
+++ b/cmdline/cmdline.h
@@ -32,7 +32,6 @@
#include "base/file_utils.h"
#include "base/logging.h"
#include "base/mutex.h"
-#include "base/string_view_cpp20.h"
#include "base/utils.h"
#include "noop_compiler_callbacks.h"
#include "oat/oat_file_assistant_context.h"
@@ -115,9 +114,9 @@ struct CmdlineArgs {
for (int i = 0; i < argc; i++) {
const char* const raw_option = argv[i];
const std::string_view option(raw_option);
- if (StartsWith(option, "--boot-image=")) {
+ if (option.starts_with("--boot-image=")) {
Split(raw_option + strlen("--boot-image="), ':', &boot_image_locations_);
- } else if (StartsWith(option, "--instruction-set=")) {
+ } else if (option.starts_with("--instruction-set=")) {
const char* const instruction_set_str = raw_option + strlen("--instruction-set=");
instruction_set_ = GetInstructionSetFromString(instruction_set_str);
if (instruction_set_ == InstructionSet::kNone) {
@@ -133,7 +132,7 @@ struct CmdlineArgs {
}
++i;
runtime_args_.push_back(argv[i]);
- } else if (StartsWith(option, "--output=")) {
+ } else if (option.starts_with("--output=")) {
output_name_ = std::string(option.substr(strlen("--output=")));
const char* filename = output_name_.c_str();
out_.reset(new std::ofstream(filename));
@@ -303,12 +302,12 @@ struct CmdlineArgs {
void ParseBootclasspath() {
std::optional<std::string_view> bcp_str = std::nullopt;
std::optional<std::string_view> bcp_location_str = std::nullopt;
- for (const char* arg : runtime_args_) {
- if (StartsWith(arg, "-Xbootclasspath:")) {
- bcp_str = arg + strlen("-Xbootclasspath:");
+ for (std::string_view arg : runtime_args_) {
+ if (arg.starts_with("-Xbootclasspath:")) {
+ bcp_str = arg.substr(strlen("-Xbootclasspath:"));
}
- if (StartsWith(arg, "-Xbootclasspath-locations:")) {
- bcp_location_str = arg + strlen("-Xbootclasspath-locations:");
+ if (arg.starts_with("-Xbootclasspath-locations:")) {
+ bcp_location_str = arg.substr(strlen("-Xbootclasspath-locations:"));
}
}
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc
index 8b415c641d..fe59d98b32 100644
--- a/compiler/driver/compiler_options.cc
+++ b/compiler/driver/compiler_options.cc
@@ -25,7 +25,6 @@
#include "arch/instruction_set_features.h"
#include "art_method-inl.h"
#include "base/runtime_debug.h"
-#include "base/string_view_cpp20.h"
#include "base/variant_map.h"
#include "class_linker.h"
#include "cmdline_parser.h"
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index 4b2f8d2e14..4ae3cd1f88 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -21,7 +21,6 @@
#include "arch/instruction_set_features.h"
#include "art_method-inl.h"
#include "base/logging.h" // For VLOG
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/time_utils.h"
#include "base/timing_logger.h"
@@ -89,7 +88,7 @@ void JitCompiler::ParseCompilerOptions() {
for (const std::string& option : runtime->GetCompilerOptions()) {
VLOG(compiler) << "JIT compiler option " << option;
std::string error_msg;
- if (StartsWith(option, "--instruction-set-variant=")) {
+ if (option.starts_with("--instruction-set-variant=")) {
const char* str = option.c_str() + strlen("--instruction-set-variant=");
VLOG(compiler) << "JIT instruction set variant " << str;
instruction_set_features = InstructionSetFeatures::FromVariantAndHwcap(
@@ -97,7 +96,7 @@ void JitCompiler::ParseCompilerOptions() {
if (instruction_set_features == nullptr) {
LOG(WARNING) << "Error parsing " << option << " message=" << error_msg;
}
- } else if (StartsWith(option, "--instruction-set-features=")) {
+ } else if (option.starts_with("--instruction-set-features=")) {
const char* str = option.c_str() + strlen("--instruction-set-features=");
VLOG(compiler) << "JIT instruction set features " << str;
if (instruction_set_features == nullptr) {
diff --git a/compiler/utils/riscv64/assembler_riscv64_test.cc b/compiler/utils/riscv64/assembler_riscv64_test.cc
index 22c380c1e0..960584070a 100644
--- a/compiler/utils/riscv64/assembler_riscv64_test.cc
+++ b/compiler/utils/riscv64/assembler_riscv64_test.cc
@@ -152,7 +152,7 @@ class AssemblerRISCV64Test : public AssemblerTest<Riscv64Assembler,
if (march_override_.has_value()) {
auto it = std::find_if(result.begin(),
result.end(),
- [](const std::string& s) { return StartsWith(s, "-march="); });
+ [](const std::string& s) { return s.starts_with("-march="); });
CHECK(it != result.end());
*it = march_override_.value();
}
diff --git a/dex2oat/dex2oat_image_test.cc b/dex2oat/dex2oat_image_test.cc
index e276638372..b62dd832fc 100644
--- a/dex2oat/dex2oat_image_test.cc
+++ b/dex2oat/dex2oat_image_test.cc
@@ -34,7 +34,6 @@
#include "base/file_utils.h"
#include "base/macros.h"
#include "base/mem_map.h"
-#include "base/string_view_cpp20.h"
#include "base/unix_file/fd_file.h"
#include "base/utils.h"
#include "dex/art_dex_file_loader.h"
@@ -129,7 +128,7 @@ class Dex2oatImageTest : public CommonRuntimeTest {
}
void CopyDexFiles(const std::string& dir, /*inout*/std::vector<std::string>* dex_files) {
- CHECK(EndsWith(dir, "/"));
+ CHECK(dir.ends_with("/"));
for (std::string& dex_file : *dex_files) {
size_t slash_pos = dex_file.rfind('/');
CHECK(OS::FileExists(dex_file.c_str())) << dex_file;
@@ -356,7 +355,7 @@ TEST_F(Dex2oatImageTest, TestExtension) {
ASSERT_FALSE(tail_ok) << error_msg;
// Now compile the tail against both "head" and "mid".
- CHECK(StartsWith(extra_args.back(), "--boot-image="));
+ CHECK(extra_args.back().starts_with("--boot-image="));
extra_args.back() = "--boot-image=" + base_location + ':' + mid_location;
tail_ok = CompileBootImage(extra_args, filename_prefix, tail_dex_files, &error_msg);
ASSERT_TRUE(tail_ok) << error_msg;
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index b5ee483e2b..fdb6d4178b 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -31,7 +31,6 @@
#include "arch/instruction_set_features.h"
#include "base/macros.h"
#include "base/mutex-inl.h"
-#include "base/string_view_cpp20.h"
#include "base/utils.h"
#include "base/zip_archive.h"
#include "common_runtime_test.h"
@@ -140,7 +139,7 @@ class Dex2oatTest : public Dex2oatEnvironmentTest {
return s == loc_arg;
}));
CHECK(std::any_of(extra_args.begin(), extra_args.end(), [](const std::string& s) {
- return StartsWith(s, "--zip-fd=");
+ return s.starts_with("--zip-fd=");
}));
} else {
dex_locations.push_back(dex_location);
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 9eb3e95b59..b01e9af495 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -37,7 +37,6 @@
#include "base/logging.h" // For VLOG
#include "base/pointer_size.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/time_utils.h"
#include "base/timing_logger.h"
@@ -2305,7 +2304,7 @@ class InitializeClassVisitor : public CompilationVisitor {
// We need to initialize static fields, we only do this for image classes that aren't
// marked with the $NoPreloadHolder (which implies this should not be initialized
// early).
- can_init_static_fields = !EndsWith(std::string_view(descriptor), "$NoPreloadHolder;");
+ can_init_static_fields = !std::string_view(descriptor).ends_with("$NoPreloadHolder;");
} else {
CHECK(is_app_image);
// The boot image case doesn't need to recursively initialize the dependencies with
@@ -2432,7 +2431,7 @@ class InitializeClassVisitor : public CompilationVisitor {
if (compiler_options.CompileArtTest()) {
// For stress testing and unit-testing the clinit check in compiled code feature.
- if (kIsDebugBuild || EndsWith(std::string_view(descriptor), "$NoPreloadHolder;")) {
+ if (kIsDebugBuild || std::string_view(descriptor).ends_with("$NoPreloadHolder;")) {
klass->SetInBootImageAndNotInPreloadedClasses();
}
}
diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc
index 2887dc9530..644be67826 100644
--- a/dexoptanalyzer/dexoptanalyzer.cc
+++ b/dexoptanalyzer/dexoptanalyzer.cc
@@ -27,7 +27,6 @@
#include "base/logging.h" // For InitLogging.
#include "base/mutex.h"
#include "base/os.h"
-#include "base/string_view_cpp20.h"
#include "base/utils.h"
#include "class_linker.h"
#include "class_loader_context.h"
@@ -164,7 +163,7 @@ class DexoptAnalyzer final {
const char* raw_option = argv[i];
const std::string_view option(raw_option);
- if (StartsWith(option, "--profile-analysis-result=")) {
+ if (option.starts_with("--profile-analysis-result=")) {
int parse_result = std::stoi(std::string(
option.substr(strlen("--profile-analysis-result="))), nullptr, 0);
if (parse_result != static_cast<int>(ProfileAnalysisResult::kOptimize) &&
@@ -173,20 +172,20 @@ class DexoptAnalyzer final {
Usage("Invalid --profile-analysis-result= %d", parse_result);
}
profile_analysis_result_ = static_cast<ProfileAnalysisResult>(parse_result);
- } else if (StartsWith(option, "--dex-file=")) {
+ } else if (option.starts_with("--dex-file=")) {
dex_file_ = std::string(option.substr(strlen("--dex-file=")));
- } else if (StartsWith(option, "--compiler-filter=")) {
+ } else if (option.starts_with("--compiler-filter=")) {
const char* filter_str = raw_option + strlen("--compiler-filter=");
if (!CompilerFilter::ParseCompilerFilter(filter_str, &compiler_filter_)) {
Usage("Invalid compiler filter '%s'", raw_option);
}
- } else if (StartsWith(option, "--isa=")) {
+ } else if (option.starts_with("--isa=")) {
const char* isa_str = raw_option + strlen("--isa=");
isa_ = GetInstructionSetFromString(isa_str);
if (isa_ == InstructionSet::kNone) {
Usage("Invalid isa '%s'", raw_option);
}
- } else if (StartsWith(option, "--image=")) {
+ } else if (option.starts_with("--image=")) {
image_ = std::string(option.substr(strlen("--image=")));
} else if (option == "--runtime-arg") {
if (i + 1 == argc) {
@@ -194,31 +193,31 @@ class DexoptAnalyzer final {
}
++i;
runtime_args_.push_back(argv[i]);
- } else if (StartsWith(option, "--android-data=")) {
+ } else if (option.starts_with("--android-data=")) {
// Overwrite android-data if needed (oat file assistant relies on a valid directory to
// compute dalvik-cache folder). This is mostly used in tests.
const char* new_android_data = raw_option + strlen("--android-data=");
setenv("ANDROID_DATA", new_android_data, 1);
} else if (option == "--downgrade") {
downgrade_ = true;
- } else if (StartsWith(option, "--oat-fd=")) {
+ } else if (option.starts_with("--oat-fd=")) {
oat_fd_ = std::stoi(std::string(option.substr(strlen("--oat-fd="))), nullptr, 0);
if (oat_fd_ < 0) {
Usage("Invalid --oat-fd %d", oat_fd_);
}
- } else if (StartsWith(option, "--vdex-fd=")) {
+ } else if (option.starts_with("--vdex-fd=")) {
vdex_fd_ = std::stoi(std::string(option.substr(strlen("--vdex-fd="))), nullptr, 0);
if (vdex_fd_ < 0) {
Usage("Invalid --vdex-fd %d", vdex_fd_);
}
- } else if (StartsWith(option, "--zip-fd=")) {
+ } else if (option.starts_with("--zip-fd=")) {
zip_fd_ = std::stoi(std::string(option.substr(strlen("--zip-fd="))), nullptr, 0);
if (zip_fd_ < 0) {
Usage("Invalid --zip-fd %d", zip_fd_);
}
- } else if (StartsWith(option, "--class-loader-context=")) {
+ } else if (option.starts_with("--class-loader-context=")) {
context_str_ = std::string(option.substr(strlen("--class-loader-context=")));
- } else if (StartsWith(option, "--class-loader-context-fds=")) {
+ } else if (option.starts_with("--class-loader-context-fds=")) {
std::string str_context_fds_arg =
std::string(option.substr(strlen("--class-loader-context-fds=")));
std::vector<std::string> str_fds = android::base::Split(str_context_fds_arg, ":");
diff --git a/imgdiag/imgdiag.cc b/imgdiag/imgdiag.cc
index 237debaa32..165f6e1565 100644
--- a/imgdiag/imgdiag.cc
+++ b/imgdiag/imgdiag.cc
@@ -35,7 +35,6 @@
#include "art_method-inl.h"
#include "base/array_ref.h"
#include "base/os.h"
-#include "base/string_view_cpp20.h"
#include "base/unix_file/fd_file.h"
#include "class_linker.h"
#include "cmdline.h"
@@ -1531,8 +1530,8 @@ class ImgDiagDumper {
for (const android::procinfo::MapInfo& map_info : maps) {
// The map name ends with ']' if it's an anonymous memmap. We need to special case that
// to find the boot image map in some cases.
- if (EndsWith(map_info.name, image_location_base_name) ||
- EndsWith(map_info.name, image_location_base_name + "]")) {
+ if (map_info.name.ends_with(image_location_base_name) ||
+ map_info.name.ends_with(image_location_base_name + "]")) {
if ((map_info.flags & PROT_WRITE) != 0) {
return map_info;
}
@@ -1866,14 +1865,14 @@ struct ImgDiagArgs : public CmdlineArgs {
}
std::string_view option(raw_option, raw_option_length);
- if (StartsWith(option, "--image-diff-pid=")) {
+ if (option.starts_with("--image-diff-pid=")) {
const char* image_diff_pid = raw_option + strlen("--image-diff-pid=");
if (!android::base::ParseInt(image_diff_pid, &image_diff_pid_)) {
*error_msg = "Image diff pid out of range";
return kParseError;
}
- } else if (StartsWith(option, "--zygote-diff-pid=")) {
+ } else if (option.starts_with("--zygote-diff-pid=")) {
const char* zygote_diff_pid = raw_option + strlen("--zygote-diff-pid=");
if (!android::base::ParseInt(zygote_diff_pid, &zygote_diff_pid_)) {
diff --git a/imgdiag/page_info.cc b/imgdiag/page_info.cc
index e5b14d4c45..025580a849 100644
--- a/imgdiag/page_info.cc
+++ b/imgdiag/page_info.cc
@@ -339,7 +339,7 @@ struct PageInfoArgs : public CmdlineArgs {
}
std::string_view option(raw_option, raw_option_length);
- if (StartsWith(option, "--pid=")) {
+ if (option.starts_with("--pid=")) {
// static_assert(std::is_signed_t
const char* value = raw_option + strlen("--pid=");
if (!android::base::ParseInt(value, &pid_)) {
@@ -348,7 +348,7 @@ struct PageInfoArgs : public CmdlineArgs {
}
} else if (option == "--count-zero-pages") {
count_zero_pages_ = true;
- } else if (StartsWith(option, "--dump-page-info=")) {
+ } else if (option.starts_with("--dump-page-info=")) {
const char* value = raw_option + strlen("--dump-page-info=");
virtual_page_index_ = 0;
if (!android::base::ParseUint(value, &virtual_page_index_.value())) {
diff --git a/libartbase/base/common_art_test.cc b/libartbase/base/common_art_test.cc
index 54069fad2e..4fc8533fa0 100644
--- a/libartbase/base/common_art_test.cc
+++ b/libartbase/base/common_art_test.cc
@@ -46,7 +46,6 @@
#include "base/runtime_debug.h"
#include "base/scoped_cap.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/testing.h"
#include "base/unix_file/fd_file.h"
#include "dex/art_dex_file_loader.h"
@@ -184,7 +183,7 @@ std::string CommonArtTestImpl::GetAndroidBuildTop() {
// We are running tests from testcases (extracted from zip) on tradefed.
// The first path is for remote runs and the second path for local runs.
if (path.filename() == std::filesystem::path("testcases") ||
- StartsWith(path.filename().string(), "host_testcases")) {
+ path.filename().string().starts_with("host_testcases")) {
android_build_top = path.append("art_common");
break;
}
@@ -482,7 +481,7 @@ std::vector<std::string> CommonArtTestImpl::GetLibCoreDexLocations(
if (IsHost()) {
std::string android_root = GetAndroidRoot();
std::string build_top = GetAndroidBuildTop();
- CHECK(android::base::StartsWith(android_root, build_top))
+ CHECK(android_root.starts_with(build_top))
<< " android_root=" << android_root << " build_top=" << build_top;
prefix = android_root.substr(build_top.size());
}
diff --git a/libartbase/base/string_view_cpp20.h b/libartbase/base/string_view_cpp20.h
deleted file mode 100644
index 9bd29d5c52..0000000000
--- a/libartbase/base/string_view_cpp20.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ART_LIBARTBASE_BASE_STRING_VIEW_CPP20_H_
-#define ART_LIBARTBASE_BASE_STRING_VIEW_CPP20_H_
-
-#include <string_view>
-
-namespace art {
-
-// When this code is only compiled on C++20+, these wrappers can be removed and
-// calling code changed to call the string_view methods directly.
-
-inline bool StartsWith(std::string_view sv, std::string_view prefix) {
-#if !defined(__cpp_lib_starts_ends_with) || __cpp_lib_starts_ends_with < 201711L
- return sv.substr(0u, prefix.size()) == prefix;
-#else
- return sv.starts_with(prefix);
-#endif
-}
-
-inline bool EndsWith(std::string_view sv, std::string_view suffix) {
-#if !defined(__cpp_lib_starts_ends_with) || __cpp_lib_starts_ends_with < 201711L
- return sv.size() >= suffix.size() && sv.substr(sv.size() - suffix.size()) == suffix;
-#else
- return sv.ends_with(suffix);
-#endif
-}
-
-} // namespace art
-
-#endif // ART_LIBARTBASE_BASE_STRING_VIEW_CPP20_H_
diff --git a/libdexfile/dex/signature.cc b/libdexfile/dex/signature.cc
index 1ab232dabf..ef76030931 100644
--- a/libdexfile/dex/signature.cc
+++ b/libdexfile/dex/signature.cc
@@ -21,8 +21,6 @@
#include <ostream>
#include <type_traits>
-#include "base/string_view_cpp20.h"
-
namespace art {
using dex::TypeList;
@@ -62,7 +60,7 @@ bool Signature::operator==(std::string_view rhs) const {
return false;
}
std::string_view tail(rhs);
- if (!StartsWith(tail, "(")) {
+ if (!tail.starts_with("(")) {
return false; // Invalid signature
}
tail.remove_prefix(1); // "(";
@@ -70,13 +68,13 @@ bool Signature::operator==(std::string_view rhs) const {
if (params != nullptr) {
for (uint32_t i = 0; i < params->Size(); ++i) {
std::string_view param = dex_file_->GetTypeDescriptorView(params->GetTypeItem(i).type_idx_);
- if (!StartsWith(tail, param)) {
+ if (!tail.starts_with(param)) {
return false;
}
tail.remove_prefix(param.length());
}
}
- if (!StartsWith(tail, ")")) {
+ if (!tail.starts_with(")")) {
return false;
}
tail.remove_prefix(1); // ")";
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index c138850a44..5131a815ad 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -48,7 +48,6 @@
#include "base/safe_map.h"
#include "base/stats-inl.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/unix_file/fd_file.h"
#include "class_linker-inl.h"
#include "class_linker.h"
@@ -3042,7 +3041,7 @@ class IMTDumper {
table_index++;
std::string p_name = ptr2->PrettyMethod(true);
- if (android::base::StartsWith(p_name, method)) {
+ if (p_name.starts_with(method)) {
std::cerr << " Slot "
<< index
<< " ("
@@ -3055,7 +3054,7 @@ class IMTDumper {
}
} else {
std::string p_name = ptr->PrettyMethod(true);
- if (android::base::StartsWith(p_name, method)) {
+ if (p_name.starts_with(method)) {
std::cerr << " Slot " << index << " (1)" << std::endl;
std::cerr << " " << p_name << std::endl;
} else {
@@ -3068,7 +3067,7 @@ class IMTDumper {
for (ArtMethod& iface_method : iface->GetMethods(pointer_size)) {
if (ImTable::GetImtIndex(&iface_method) == index) {
std::string i_name = iface_method.PrettyMethod(true);
- if (android::base::StartsWith(i_name, method)) {
+ if (i_name.starts_with(method)) {
std::cerr << " Slot " << index << " (1)" << std::endl;
std::cerr << " " << p_name << " (" << i_name << ")" << std::endl;
}
@@ -3087,7 +3086,7 @@ class IMTDumper {
while (in_stream.good()) {
std::string dot;
std::getline(in_stream, dot);
- if (android::base::StartsWith(dot, "#") || dot.empty()) {
+ if (dot.starts_with("#") || dot.empty()) {
continue;
}
output.push_back(dot);
@@ -3159,11 +3158,11 @@ struct OatdumpArgs : public CmdlineArgs {
}
std::string_view option(raw_option, raw_option_length);
- if (StartsWith(option, "--oat-file=")) {
+ if (option.starts_with("--oat-file=")) {
oat_filename_ = raw_option + strlen("--oat-file=");
- } else if (StartsWith(option, "--dex-file=")) {
+ } else if (option.starts_with("--dex-file=")) {
dex_filename_ = raw_option + strlen("--dex-file=");
- } else if (StartsWith(option, "--image=")) {
+ } else if (option.starts_with("--image=")) {
image_location_ = raw_option + strlen("--image=");
} else if (option == "--no-dump:vmap") {
dump_vmap_ = false;
@@ -3173,31 +3172,31 @@ struct OatdumpArgs : public CmdlineArgs {
disassemble_code_ = false;
} else if (option =="--header-only") {
dump_header_only_ = true;
- } else if (StartsWith(option, "--symbolize=")) {
+ } else if (option.starts_with("--symbolize=")) {
oat_filename_ = raw_option + strlen("--symbolize=");
symbolize_ = true;
- } else if (StartsWith(option, "--only-keep-debug")) {
+ } else if (option.starts_with("--only-keep-debug")) {
only_keep_debug_ = true;
- } else if (StartsWith(option, "--class-filter=")) {
+ } else if (option.starts_with("--class-filter=")) {
class_filter_ = raw_option + strlen("--class-filter=");
- } else if (StartsWith(option, "--method-filter=")) {
+ } else if (option.starts_with("--method-filter=")) {
method_filter_ = raw_option + strlen("--method-filter=");
- } else if (StartsWith(option, "--list-classes")) {
+ } else if (option.starts_with("--list-classes")) {
list_classes_ = true;
- } else if (StartsWith(option, "--list-methods")) {
+ } else if (option.starts_with("--list-methods")) {
list_methods_ = true;
- } else if (StartsWith(option, "--export-dex-to=")) {
+ } else if (option.starts_with("--export-dex-to=")) {
export_dex_location_ = raw_option + strlen("--export-dex-to=");
- } else if (StartsWith(option, "--addr2instr=")) {
+ } else if (option.starts_with("--addr2instr=")) {
if (!android::base::ParseUint(raw_option + strlen("--addr2instr="), &addr2instr_)) {
*error_msg = "Address conversion failed";
return kParseError;
}
- } else if (StartsWith(option, "--app-image=")) {
+ } else if (option.starts_with("--app-image=")) {
app_image_ = raw_option + strlen("--app-image=");
- } else if (StartsWith(option, "--app-oat=")) {
+ } else if (option.starts_with("--app-oat=")) {
app_oat_ = raw_option + strlen("--app-oat=");
- } else if (StartsWith(option, "--dump-imt=")) {
+ } else if (option.starts_with("--dump-imt=")) {
imt_dump_ = std::string(option.substr(strlen("--dump-imt=")));
} else if (option == "--dump-imt-stats") {
imt_stat_dump_ = true;
diff --git a/odrefresh/odr_artifacts_test.cc b/odrefresh/odr_artifacts_test.cc
index b47f2a7e3e..0131e23a3d 100644
--- a/odrefresh/odr_artifacts_test.cc
+++ b/odrefresh/odr_artifacts_test.cc
@@ -19,7 +19,6 @@
#include "arch/instruction_set.h"
#include "base/common_art_test.h"
#include "base/file_utils.h"
-#include "base/string_view_cpp20.h"
#include "odrefresh/odrefresh.h"
namespace art {
@@ -32,7 +31,7 @@ TEST(OdrArtifactsTest, ForBootImage) {
setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1);
const std::string image_location = GetApexDataBootImage("/system/framework/framework.jar");
- EXPECT_TRUE(StartsWith(image_location, GetArtApexData()));
+ EXPECT_TRUE(image_location.starts_with(GetArtApexData()));
const std::string image_filename =
GetSystemImageFilename(image_location.c_str(), InstructionSet::kArm64);
@@ -51,7 +50,7 @@ TEST(OdrArtifactsTest, ForSystemServer) {
setenv("ART_APEX_DATA", kOdrefreshArtifactDirectory, /* overwrite */ 1);
const std::string image_location = GetApexDataImage("/system/framework/services.jar");
- EXPECT_TRUE(StartsWith(image_location, GetArtApexData()));
+ EXPECT_TRUE(image_location.starts_with(GetArtApexData()));
const std::string image_filename =
GetSystemImageFilename(image_location.c_str(), InstructionSet::kX86);
diff --git a/odrefresh/odr_metrics.cc b/odrefresh/odr_metrics.cc
index a4533d9124..2a81214221 100644
--- a/odrefresh/odr_metrics.cc
+++ b/odrefresh/odr_metrics.cc
@@ -28,7 +28,6 @@
#include <android-base/logging.h>
#include <base/os.h>
-#include <base/string_view_cpp20.h>
#include <odr_fs_utils.h>
#include <odr_metrics_record.h>
@@ -37,7 +36,7 @@ namespace odrefresh {
OdrMetrics::OdrMetrics(const std::string& cache_directory, const std::string& metrics_file)
: cache_directory_(cache_directory), metrics_file_(metrics_file) {
- DCHECK(StartsWith(metrics_file_, "/"));
+ DCHECK(metrics_file.starts_with("/"));
// Remove existing metrics file if it exists.
if (OS::FileExists(metrics_file.c_str())) {
diff --git a/profman/profman.cc b/profman/profman.cc
index b56fdf2523..1525b476cd 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -42,7 +42,6 @@
#include "base/mem_map.h"
#include "base/scoped_flock.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/time_utils.h"
#include "base/unix_file/fd_file.h"
#include "base/utils.h"
@@ -260,20 +259,21 @@ static void ParseUintOption(const char* raw_option,
T* out,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max()) {
- DCHECK(EndsWith(option_prefix, "="));
- DCHECK(StartsWith(raw_option, option_prefix)) << raw_option << " " << option_prefix;
+ DCHECK(option_prefix.ends_with("="));
+ DCHECK(std::string_view(raw_option).starts_with(option_prefix))
+ << raw_option << " " << option_prefix;
std::string option_name(option_prefix.substr(option_prefix.size() - 1u));
const char* value_string = raw_option + option_prefix.size();
ParseUintValue(option_name, value_string, out, min, max);
}
-static void ParseBoolOption(const char* raw_option,
+static void ParseBoolOption(std::string_view option,
std::string_view option_prefix,
bool* out) {
- DCHECK(EndsWith(option_prefix, "="));
- DCHECK(StartsWith(raw_option, option_prefix)) << raw_option << " " << option_prefix;
- const char* value_string = raw_option + option_prefix.size();
+ DCHECK(option_prefix.ends_with("="));
+ DCHECK(option.starts_with(option_prefix)) << option << " " << option_prefix;
+ const std::string_view value_string = option.substr(option_prefix.size());
android::base::ParseBoolResult result = android::base::ParseBool(value_string);
if (result == android::base::ParseBoolResult::kError) {
std::string option_name(option_prefix.substr(option_prefix.size() - 1u));
@@ -289,17 +289,17 @@ enum class OutputProfileType {
kBprof,
};
-static void ParseOutputProfileType(const char* raw_option,
+static void ParseOutputProfileType(std::string_view option,
std::string_view option_prefix,
OutputProfileType* out) {
- DCHECK(EndsWith(option_prefix, "="));
- DCHECK(StartsWith(raw_option, option_prefix)) << raw_option << " " << option_prefix;
- const char* value_string = raw_option + option_prefix.size();
- if (strcmp(value_string, "app") == 0) {
+ DCHECK(option_prefix.ends_with("="));
+ DCHECK(option.starts_with(option_prefix)) << option << " " << option_prefix;
+ const std::string_view value_string = option.substr(option_prefix.size());
+ if (value_string == "app") {
*out = OutputProfileType::kApp;
- } else if (strcmp(value_string, "boot") == 0) {
+ } else if (value_string == "boot") {
*out = OutputProfileType::kBoot;
- } else if (strcmp(value_string, "bprof") == 0) {
+ } else if (value_string == "bprof") {
*out = OutputProfileType::kBprof;
} else {
std::string option_name(option_prefix.substr(option_prefix.size() - 1u));
@@ -356,39 +356,39 @@ class ProfMan final {
dump_only_ = true;
} else if (option == "--dump-classes-and-methods") {
dump_classes_and_methods_ = true;
- } else if (StartsWith(option, "--create-profile-from=")) {
+ } else if (option.starts_with("--create-profile-from=")) {
create_profile_from_file_ = std::string(option.substr(strlen("--create-profile-from=")));
- } else if (StartsWith(option, "--output-profile-type=")) {
- ParseOutputProfileType(raw_option, "--output-profile-type=", &output_profile_type_);
- } else if (StartsWith(option, "--dump-output-to-fd=")) {
+ } else if (option.starts_with("--output-profile-type=")) {
+ ParseOutputProfileType(option, "--output-profile-type=", &output_profile_type_);
+ } else if (option.starts_with("--dump-output-to-fd=")) {
ParseUintOption(raw_option, "--dump-output-to-fd=", &dump_output_to_fd_);
} else if (option == "--generate-boot-image-profile") {
generate_boot_image_profile_ = true;
- } else if (StartsWith(option, "--method-threshold=")) {
+ } else if (option.starts_with("--method-threshold=")) {
ParseUintOption(raw_option,
"--method-threshold=",
&boot_image_options_.method_threshold,
0u,
100u);
- } else if (StartsWith(option, "--class-threshold=")) {
+ } else if (option.starts_with("--class-threshold=")) {
ParseUintOption(raw_option,
"--class-threshold=",
&boot_image_options_.image_class_threshold,
0u,
100u);
- } else if (StartsWith(option, "--clean-class-threshold=")) {
+ } else if (option.starts_with("--clean-class-threshold=")) {
ParseUintOption(raw_option,
"--clean-class-threshold=",
&boot_image_options_.image_class_clean_threshold,
0u,
100u);
- } else if (StartsWith(option, "--preloaded-class-threshold=")) {
+ } else if (option.starts_with("--preloaded-class-threshold=")) {
ParseUintOption(raw_option,
"--preloaded-class-threshold=",
&boot_image_options_.preloaded_class_threshold,
0u,
100u);
- } else if (StartsWith(option, "--preloaded-classes-denylist=")) {
+ } else if (option.starts_with("--preloaded-classes-denylist=")) {
std::string preloaded_classes_denylist =
std::string(option.substr(strlen("--preloaded-classes-denylist=")));
// Read the user-specified list of methods.
@@ -397,11 +397,11 @@ class ProfMan final {
preloaded_classes_denylist.c_str(), nullptr)); // No post-processing.
boot_image_options_.preloaded_classes_denylist.insert(
denylist->begin(), denylist->end());
- } else if (StartsWith(option, "--upgrade-startup-to-hot=")) {
- ParseBoolOption(raw_option,
+ } else if (option.starts_with("--upgrade-startup-to-hot=")) {
+ ParseBoolOption(option,
"--upgrade-startup-to-hot=",
&boot_image_options_.upgrade_startup_to_hot);
- } else if (StartsWith(option, "--special-package=")) {
+ } else if (option.starts_with("--special-package=")) {
std::vector<std::string> values;
Split(std::string(option.substr(strlen("--special-package="))), ':', &values);
if (values.size() != 2) {
@@ -410,46 +410,46 @@ class ProfMan final {
uint32_t threshold;
ParseUintValue("special-package", values[1], &threshold, 0u, 100u);
boot_image_options_.special_packages_thresholds.Overwrite(values[0], threshold);
- } else if (StartsWith(option, "--debug-append-uses=")) {
- ParseBoolOption(raw_option,
+ } else if (option.starts_with("--debug-append-uses=")) {
+ ParseBoolOption(option,
"--debug-append-uses=",
&boot_image_options_.append_package_use_list);
- } else if (StartsWith(option, "--out-profile-path=")) {
+ } else if (option.starts_with("--out-profile-path=")) {
boot_profile_out_path_ = std::string(option.substr(strlen("--out-profile-path=")));
- } else if (StartsWith(option, "--out-preloaded-classes-path=")) {
+ } else if (option.starts_with("--out-preloaded-classes-path=")) {
preloaded_classes_out_path_ = std::string(
option.substr(strlen("--out-preloaded-classes-path=")));
- } else if (StartsWith(option, "--profile-file=")) {
+ } else if (option.starts_with("--profile-file=")) {
profile_files_.push_back(std::string(option.substr(strlen("--profile-file="))));
- } else if (StartsWith(option, "--profile-file-fd=")) {
+ } else if (option.starts_with("--profile-file-fd=")) {
ParseFdForCollection(raw_option, "--profile-file-fd=", &profile_files_fd_);
- } else if (StartsWith(option, "--reference-profile-file=")) {
+ } else if (option.starts_with("--reference-profile-file=")) {
reference_profile_file_ = std::string(option.substr(strlen("--reference-profile-file=")));
- } else if (StartsWith(option, "--reference-profile-file-fd=")) {
+ } else if (option.starts_with("--reference-profile-file-fd=")) {
ParseUintOption(raw_option, "--reference-profile-file-fd=", &reference_profile_file_fd_);
- } else if (StartsWith(option, "--dex-location=")) {
+ } else if (option.starts_with("--dex-location=")) {
dex_locations_.push_back(std::string(option.substr(strlen("--dex-location="))));
- } else if (StartsWith(option, "--apk-fd=")) {
+ } else if (option.starts_with("--apk-fd=")) {
ParseFdForCollection(raw_option, "--apk-fd=", &apks_fd_);
- } else if (StartsWith(option, "--apk=")) {
+ } else if (option.starts_with("--apk=")) {
apk_files_.push_back(std::string(option.substr(strlen("--apk="))));
- } else if (StartsWith(option, "--generate-test-profile=")) {
+ } else if (option.starts_with("--generate-test-profile=")) {
test_profile_ = std::string(option.substr(strlen("--generate-test-profile=")));
- } else if (StartsWith(option, "--generate-test-profile-num-dex=")) {
+ } else if (option.starts_with("--generate-test-profile-num-dex=")) {
ParseUintOption(raw_option,
"--generate-test-profile-num-dex=",
&test_profile_num_dex_);
- } else if (StartsWith(option, "--generate-test-profile-method-percentage=")) {
+ } else if (option.starts_with("--generate-test-profile-method-percentage=")) {
ParseUintOption(raw_option,
"--generate-test-profile-method-percentage=",
&test_profile_method_percerntage_);
- } else if (StartsWith(option, "--generate-test-profile-class-percentage=")) {
+ } else if (option.starts_with("--generate-test-profile-class-percentage=")) {
ParseUintOption(raw_option,
"--generate-test-profile-class-percentage=",
&test_profile_class_percentage_);
- } else if (StartsWith(option, "--generate-test-profile-seed=")) {
+ } else if (option.starts_with("--generate-test-profile-seed=")) {
ParseUintOption(raw_option, "--generate-test-profile-seed=", &test_profile_seed_);
- } else if (StartsWith(option, "--min-new-methods-percent-change=")) {
+ } else if (option.starts_with("--min-new-methods-percent-change=")) {
uint32_t min_new_methods_percent_change;
ParseUintOption(raw_option,
"--min-new-methods-percent-change=",
@@ -458,7 +458,7 @@ class ProfMan final {
100u);
profile_assistant_options_.SetMinNewMethodsPercentChangeForCompilation(
min_new_methods_percent_change);
- } else if (StartsWith(option, "--min-new-classes-percent-change=")) {
+ } else if (option.starts_with("--min-new-classes-percent-change=")) {
uint32_t min_new_classes_percent_change;
ParseUintOption(raw_option,
"--min-new-classes-percent-change=",
@@ -1050,7 +1050,7 @@ class ProfMan final {
while (in_stream.good()) {
std::string dot;
std::getline(in_stream, dot);
- if (android::base::StartsWith(dot, "#") || dot.empty()) {
+ if (dot.starts_with("#") || dot.empty()) {
continue;
}
if (process != nullptr) {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 52caa9f1cf..c8394b2a5d 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -56,7 +56,6 @@
#include "base/scoped_arena_containers.h"
#include "base/scoped_flock.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/time_utils.h"
#include "base/unix_file/fd_file.h"
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index ec7abb75ac..59740a71ec 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -29,7 +29,6 @@
#include "art_method-alloc-inl.h"
#include "base/dchecked_vector.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "class_linker.h"
#include "class_root-inl.h"
#include "common_runtime_test.h"
@@ -210,7 +209,7 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
// If the opened location is relative (it was open from a relative path without a
// classpath_dir) it might not match the expected location which is absolute in tests).
// So we compare the endings (the checksum will validate it's actually the same file).
- ASSERT_TRUE(EndsWith(expected_location, opened_location))
+ ASSERT_TRUE(expected_location.ends_with(opened_location))
<< expected_location << " " << opened_location;
} else {
ASSERT_EQ(expected_location, opened_location);
@@ -234,7 +233,7 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
// If the opened location is relative (it was open from a relative path without a
// classpath_dir) it might not match the expected location which is absolute in tests).
// So we compare the endings (the checksum will validate it's actually the same file).
- ASSERT_TRUE(EndsWith(expected_location, opened_location))
+ ASSERT_TRUE(expected_location.ends_with(opened_location))
<< expected_location << " " << opened_location;
} else {
ASSERT_EQ(expected_location, opened_location);
@@ -377,7 +376,7 @@ class ClassLoaderContextTest : public CommonRuntimeTest {
// TODO We should somehow support this in all situations. b/72042237.
bool CreateRelativeString(const std::string& in, const char* cwd, std::string* out) {
int cwd_len = strlen(cwd);
- if (!android::base::StartsWith(in, cwd) || (cwd_len < 1)) {
+ if (!in.starts_with(cwd) || (cwd_len < 1)) {
return false;
}
bool contains_trailing_slash = (cwd[cwd_len - 1] == '/');
diff --git a/runtime/compat_framework.h b/runtime/compat_framework.h
index 1e71362b5a..1fb1a72813 100644
--- a/runtime/compat_framework.h
+++ b/runtime/compat_framework.h
@@ -21,7 +21,6 @@
#include "base/macros.h"
#include "base/mutex.h"
-#include "base/string_view_cpp20.h"
namespace art HIDDEN {
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index f8f1ac0165..4333d08452 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -44,7 +44,6 @@
#include "base/os.h"
#include "base/pointer_size.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/time_utils.h"
#include "base/utils.h"
@@ -1472,7 +1471,7 @@ static bool CheckAndRemoveImageChecksum(uint32_t component_count,
/*out*/std::string* error_msg) {
std::string image_checksum;
ImageSpace::AppendImageChecksum(component_count, checksum, &image_checksum);
- if (!StartsWith(*oat_checksums, image_checksum)) {
+ if (!oat_checksums->starts_with(image_checksum)) {
*error_msg = StringPrintf("Image checksum mismatch, expected %s to start with %s",
std::string(*oat_checksums).c_str(),
image_checksum.c_str());
@@ -2184,7 +2183,7 @@ bool ImageSpace::BootImageLayout::Load(FilenameFn&& filename_fn,
DCHECK_NE(slash_pos, std::string::npos);
base_location = bcp_component.substr(0u, slash_pos + 1u) + base_name;
} else {
- DCHECK(EndsWith(path, "/*"));
+ DCHECK(path.ends_with("/*"));
base_location = path.substr(0u, path.size() - 1u) + base_name;
}
std::string err_msg; // Ignored.
@@ -3415,7 +3414,7 @@ bool ImageSpace::ValidateApexVersions(const OatHeader& oat_header,
// For a boot image, it can be generated from a subset of the bootclasspath.
// For an app image, some dex files get compiled with a subset of the bootclasspath.
// For such cases, the OAT APEX versions will be a prefix of the runtime APEX versions.
- if (!android::base::StartsWith(apex_versions, oat_apex_versions)) {
+ if (!apex_versions.starts_with(oat_apex_versions)) {
*error_msg = StringPrintf(
"ValidateApexVersions found APEX versions mismatch between oat file '%s' and the runtime "
"(Oat file: '%s', Runtime: '%s')",
@@ -3569,7 +3568,7 @@ size_t ImageSpace::CheckAndCountBCPComponents(std::string_view oat_boot_class_pa
std::string_view remaining_bcp(oat_boot_class_path);
bool bcp_ok = false;
for (const std::string& location : boot_class_path) {
- if (!StartsWith(remaining_bcp, location)) {
+ if (!remaining_bcp.starts_with(location)) {
break;
}
remaining_bcp.remove_prefix(location.size());
@@ -3578,7 +3577,7 @@ size_t ImageSpace::CheckAndCountBCPComponents(std::string_view oat_boot_class_pa
bcp_ok = true;
break;
}
- if (!StartsWith(remaining_bcp, ":")) {
+ if (!remaining_bcp.starts_with(":")) {
break;
}
remaining_bcp.remove_prefix(1u);
@@ -3629,7 +3628,7 @@ bool ImageSpace::VerifyBootClassPathChecksums(
// Verify image checksums.
size_t bcp_pos = 0u;
size_t image_pos = 0u;
- while (image_pos != num_image_spaces && StartsWith(oat_checksums, "i")) {
+ while (image_pos != num_image_spaces && oat_checksums.starts_with("i")) {
// Verify the current image checksum.
const ImageHeader& current_header = image_spaces[image_pos]->GetImageHeader();
uint32_t image_space_count = current_header.GetImageSpaceCount();
@@ -3667,7 +3666,7 @@ bool ImageSpace::VerifyBootClassPathChecksums(
image_pos += image_space_count;
bcp_pos += component_count;
- if (!StartsWith(oat_checksums, ":")) {
+ if (!oat_checksums.starts_with(":")) {
// Check that we've reached the end of checksums and BCP.
if (!oat_checksums.empty()) {
*error_msg = StringPrintf("Expected ':' separator or end of checksums, remaining %s.",
diff --git a/runtime/hidden_api_test.cc b/runtime/hidden_api_test.cc
index 96a5822973..eff54bd861 100644
--- a/runtime/hidden_api_test.cc
+++ b/runtime/hidden_api_test.cc
@@ -201,7 +201,7 @@ class HiddenApiTest : public CommonRuntimeTest {
// that may run in parallel. b/238730923
const std::string_view suffix = ".jar";
const std::string_view placeholder = "XXXXXX"; // See `mkstemps()`.
- ASSERT_TRUE(EndsWith(location, suffix));
+ ASSERT_TRUE(location.ends_with(suffix));
std::unique_ptr<char[]> unique_location(new char[location.length() + placeholder.length() + 1]);
ASSERT_TRUE(unique_location != nullptr);
size_t stem_length = location.length() - suffix.length();
diff --git a/runtime/jni/java_vm_ext.cc b/runtime/jni/java_vm_ext.cc
index 4b58fd883e..60b436984d 100644
--- a/runtime/jni/java_vm_ext.cc
+++ b/runtime/jni/java_vm_ext.cc
@@ -26,7 +26,6 @@
#include "base/mutex-inl.h"
#include "base/sdk_version.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "check_jni.h"
#include "dex/dex_file-inl.h"
@@ -640,7 +639,7 @@ bool JavaVMExt::ShouldTrace(ArtMethod* method) {
"Lorg/apache/harmony/",
};
for (size_t i = 0; i < arraysize(gBuiltInPrefixes); ++i) {
- if (StartsWith(class_name, gBuiltInPrefixes[i])) {
+ if (class_name.starts_with(gBuiltInPrefixes[i])) {
return false;
}
}
diff --git a/runtime/oat/oat_file.cc b/runtime/oat/oat_file.cc
index 8a6ab21c76..655591f879 100644
--- a/runtime/oat/oat_file.cc
+++ b/runtime/oat/oat_file.cc
@@ -47,7 +47,6 @@
#include "base/os.h"
#include "base/pointer_size.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/unix_file/fd_file.h"
#include "base/utils.h"
@@ -758,7 +757,7 @@ bool OatFileBase::Setup(int zip_fd,
}
// Check that the base location of a multidex location matches the last seen primary location.
if (is_multidex &&
- (!StartsWith(dex_file_location, primary_location) ||
+ (!dex_file_location.starts_with(primary_location) ||
dex_file_location[primary_location.size()] != DexFileLoader::kMultiDexSeparator)) {
*error_msg = ErrorPrintf("unexpected multidex location '%s', unrelated to '%s'",
dex_file_location.c_str(),
@@ -774,7 +773,7 @@ bool OatFileBase::Setup(int zip_fd,
if (dex_file_location.find('/') == std::string::npos &&
dex_file_name.size() > dex_file_location.size() &&
dex_file_name[dex_file_name.size() - dex_file_location.size() - 1u] == '/' &&
- EndsWith(dex_file_name, dex_file_location)) {
+ dex_file_name.ends_with(dex_file_location)) {
dex_file_location = dex_file_name;
}
}
diff --git a/runtime/oat/oat_file_assistant.cc b/runtime/oat/oat_file_assistant.cc
index 5ddee8d616..8fcf1c8f57 100644
--- a/runtime/oat/oat_file_assistant.cc
+++ b/runtime/oat/oat_file_assistant.cc
@@ -37,7 +37,6 @@
#include "base/macros.h"
#include "base/os.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/systrace.h"
#include "base/utils.h"
#include "base/zip_archive.h"
@@ -588,8 +587,8 @@ bool OatFileAssistant::IsAnonymousVdexBasename(const std::string& basename) {
DCHECK(basename.find('/') == std::string::npos);
// `basename` must have format: <kAnonymousDexPrefix><checksum><kVdexExtension>
if (basename.size() < strlen(kAnonymousDexPrefix) + strlen(kVdexExtension) + 1 ||
- !android::base::StartsWith(basename, kAnonymousDexPrefix) ||
- !android::base::EndsWith(basename, kVdexExtension)) {
+ !basename.starts_with(kAnonymousDexPrefix) ||
+ !basename.ends_with(kVdexExtension)) {
return false;
}
// Check that all characters between the prefix and extension are decimal digits.
@@ -767,7 +766,7 @@ bool OatFileAssistant::ValidateBootClassPathChecksums(OatFileAssistantContext* o
while (bcp_index < oat_bcp_size) {
static_assert(gc::space::ImageSpace::kImageChecksumPrefix == 'i', "Format prefix check");
static_assert(gc::space::ImageSpace::kDexFileChecksumPrefix == 'd', "Format prefix check");
- if (StartsWith(oat_checksums, "i") && !found_d) {
+ if (oat_checksums.starts_with("i") && !found_d) {
const std::vector<OatFileAssistantContext::BootImageInfo>& boot_image_info_list =
ofa_context->GetBootImageInfoList(isa);
if (boot_image_index >= boot_image_info_list.size()) {
@@ -788,7 +787,7 @@ bool OatFileAssistant::ValidateBootClassPathChecksums(OatFileAssistantContext* o
bcp_index += boot_image_info.component_count;
boot_image_index++;
- } else if (StartsWith(oat_checksums, "d")) {
+ } else if (oat_checksums.starts_with("d")) {
found_d = true;
const std::vector<std::string>* bcp_checksums =
ofa_context->GetBcpChecksums(bcp_index, error_msg);
@@ -1057,7 +1056,7 @@ const OatFile* OatFileAssistant::OatFileInfo::GetFile() {
std::string error_msg;
bool executable = oat_file_assistant_->load_executable_;
- if (android::base::EndsWith(filename_, kVdexExtension)) {
+ if (filename_.ends_with(kVdexExtension)) {
executable = false;
// Check to see if there is a vdex file we can make use of.
std::unique_ptr<VdexFile> vdex;
@@ -1091,7 +1090,7 @@ const OatFile* OatFileAssistant::OatFileInfo::GetFile() {
oat_file_assistant_->context_,
&error_msg));
}
- } else if (android::base::EndsWith(filename_, kDmExtension)) {
+ } else if (filename_.ends_with(kDmExtension)) {
executable = false;
// Check to see if there is a vdex file we can make use of.
std::unique_ptr<ZipArchive> dm_file(ZipArchive::Open(filename_.c_str(), &error_msg));
@@ -1186,7 +1185,7 @@ bool OatFileAssistant::OatFileInfo::ShouldRecompileForFilter(CompilerFilter::Fil
const char* oat_boot_class_path_checksums =
file->GetOatHeader().GetStoreValueByKey(OatHeader::kBootClassPathChecksumsKey);
if (oat_boot_class_path_checksums != nullptr &&
- !StartsWith(oat_boot_class_path_checksums, "i") &&
+ oat_boot_class_path_checksums[0] != 'i' &&
oat_file_assistant_->IsPrimaryBootImageUsable()) {
DCHECK(!file->GetOatHeader().RequiresImage());
VLOG(oat) << "Should recompile: primaryBootImageBecomesUsable";
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 96f76652d2..89020ef5ae 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -34,7 +34,6 @@
#include "base/mem_map.h"
#include "base/metrics/metrics.h"
#include "base/os.h"
-#include "base/string_view_cpp20.h"
#include "base/unix_file/fd_file.h"
#include "compat_framework.h"
#include "deoptimization_kind.h"
diff --git a/tools/art_verifier/art_verifier.cc b/tools/art_verifier/art_verifier.cc
index e68d2ca3d5..f5d957683a 100644
--- a/tools/art_verifier/art_verifier.cc
+++ b/tools/art_verifier/art_verifier.cc
@@ -102,7 +102,7 @@ struct MethodVerifierArgs : public CmdlineArgs {
}
std::string_view option(raw_option, raw_option_length);
- if (StartsWith(option, "--dex-file=")) {
+ if (option.starts_with("--dex-file=")) {
dex_filename_ = raw_option + strlen("--dex-file=");
} else if (option == "--dex-file-verifier") {
dex_file_verifier_ = true;
@@ -110,10 +110,10 @@ struct MethodVerifierArgs : public CmdlineArgs {
method_verifier_verbose_ = true;
} else if (option == "--verbose-debug") {
method_verifier_verbose_debug_ = true;
- } else if (StartsWith(option, "--repetitions=")) {
+ } else if (option.starts_with("--repetitions=")) {
char* end;
repetitions_ = strtoul(raw_option + strlen("--repetitions="), &end, 10);
- } else if (StartsWith(option, "--api-level=")) {
+ } else if (option.starts_with("--api-level=")) {
char* end;
api_level_ = strtoul(raw_option + strlen("--api-level="), &end, 10);
} else {
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index 85be3ed555..bc73865019 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -32,7 +32,6 @@
#include "base/mem_map.h"
#include "base/os.h"
#include "base/stl_util.h"
-#include "base/string_view_cpp20.h"
#include "base/unix_file/fd_file.h"
#include "dex/art_dex_file_loader.h"
#include "dex/class_accessor-inl.h"
@@ -807,15 +806,15 @@ class HiddenApi final {
for (int i = 1; i < argc; ++i) {
const char* raw_option = argv[i];
const std::string_view option(raw_option);
- if (StartsWith(option, "--input-dex=")) {
+ if (option.starts_with("--input-dex=")) {
boot_dex_paths_.push_back(std::string(option.substr(strlen("--input-dex="))));
- } else if (StartsWith(option, "--output-dex=")) {
+ } else if (option.starts_with("--output-dex=")) {
output_dex_paths_.push_back(std::string(option.substr(strlen("--output-dex="))));
- } else if (StartsWith(option, "--api-flags=")) {
+ } else if (option.starts_with("--api-flags=")) {
api_flags_path_ = std::string(option.substr(strlen("--api-flags=")));
} else if (option == "--no-force-assign-all") {
force_assign_all_ = false;
- } else if (StartsWith(option, "--max-hiddenapi-level=")) {
+ } else if (option.starts_with("--max-hiddenapi-level=")) {
std::string value = std::string(option.substr(strlen("--max-hiddenapi-level=")));
max_hiddenapi_level_ = ApiList::FromName(value);
} else {
@@ -827,30 +826,30 @@ class HiddenApi final {
for (int i = 1; i < argc; ++i) {
const char* raw_option = argv[i];
const std::string_view option(raw_option);
- if (StartsWith(option, "--dependency-stub-dex=")) {
+ if (option.starts_with("--dependency-stub-dex=")) {
const std::string path(std::string(option.substr(strlen("--dependency-stub-dex="))));
dependency_stub_dex_paths_.push_back(path);
// Add path to the boot dex path to resolve dependencies.
boot_dex_paths_.push_back(path);
- } else if (StartsWith(option, "--boot-dex=")) {
+ } else if (option.starts_with("--boot-dex=")) {
boot_dex_paths_.push_back(std::string(option.substr(strlen("--boot-dex="))));
- } else if (StartsWith(option, "--public-stub-classpath=")) {
+ } else if (option.starts_with("--public-stub-classpath=")) {
stub_classpaths_.push_back(std::make_pair(
std::string(option.substr(strlen("--public-stub-classpath="))),
ApiStubs::Kind::kPublicApi));
- } else if (StartsWith(option, "--system-stub-classpath=")) {
+ } else if (option.starts_with("--system-stub-classpath=")) {
stub_classpaths_.push_back(std::make_pair(
std::string(option.substr(strlen("--system-stub-classpath="))),
ApiStubs::Kind::kSystemApi));
- } else if (StartsWith(option, "--test-stub-classpath=")) {
+ } else if (option.starts_with("--test-stub-classpath=")) {
stub_classpaths_.push_back(std::make_pair(
std::string(option.substr(strlen("--test-stub-classpath="))),
ApiStubs::Kind::kTestApi));
- } else if (StartsWith(option, "--core-platform-stub-classpath=")) {
+ } else if (option.starts_with("--core-platform-stub-classpath=")) {
stub_classpaths_.push_back(std::make_pair(
std::string(option.substr(strlen("--core-platform-stub-classpath="))),
ApiStubs::Kind::kCorePlatformApi));
- } else if (StartsWith(option, "--out-api-flags=")) {
+ } else if (option.starts_with("--out-api-flags=")) {
api_flags_path_ = std::string(option.substr(strlen("--out-api-flags=")));
} else if (option == "--fragment") {
fragment_ = true;