Replace StringPiece with std::string_view in art/runtime/.
And in art/test/.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 123750182
Change-Id: I14c7cddd7ba4fb2183c643d32a89b594008d8bd0
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index a2775d2..c9bdbda 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -18,6 +18,7 @@
#include <memory>
#include <string>
+#include <string_view>
#include "android-base/strings.h"
@@ -509,7 +510,7 @@
for (size_t i = 0; i < offsets.size(); i++) {
ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
- StringPiece field_name(field->GetName());
+ std::string_view field_name(field->GetName());
if (field_name != offsets[i].java_name) {
error = true;
}
@@ -518,7 +519,7 @@
for (size_t i = 0; i < offsets.size(); i++) {
CheckOffset& offset = offsets[i];
ArtField* field = is_static ? klass->GetStaticField(i) : klass->GetInstanceField(i);
- StringPiece field_name(field->GetName());
+ std::string_view field_name(field->GetName());
if (field_name != offsets[i].java_name) {
LOG(ERROR) << "JAVA FIELD ORDER MISMATCH NEXT LINE:";
}
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 62788b1..499bf28 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -390,8 +390,10 @@
// NoSuchFieldError
-void ThrowNoSuchFieldError(const StringPiece& scope, ObjPtr<mirror::Class> c,
- const StringPiece& type, const StringPiece& name) {
+void ThrowNoSuchFieldError(std::string_view scope,
+ ObjPtr<mirror::Class> c,
+ std::string_view type,
+ std::string_view name) {
std::ostringstream msg;
std::string temp;
msg << "No " << scope << "field " << name << " of type " << type
@@ -399,7 +401,7 @@
ThrowException("Ljava/lang/NoSuchFieldError;", c, msg.str().c_str());
}
-void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name) {
+void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, std::string_view name) {
std::ostringstream msg;
std::string temp;
msg << "No field " << name << " in class " << c->GetDescriptor(&temp);
@@ -408,7 +410,9 @@
// NoSuchMethodError
-void ThrowNoSuchMethodError(InvokeType type, ObjPtr<mirror::Class> c, const StringPiece& name,
+void ThrowNoSuchMethodError(InvokeType type,
+ ObjPtr<mirror::Class> c,
+ std::string_view name,
const Signature& signature) {
std::ostringstream msg;
std::string temp;
diff --git a/runtime/common_throws.h b/runtime/common_throws.h
index ca9c96a..c167d1b 100644
--- a/runtime/common_throws.h
+++ b/runtime/common_throws.h
@@ -17,6 +17,8 @@
#ifndef ART_RUNTIME_COMMON_THROWS_H_
#define ART_RUNTIME_COMMON_THROWS_H_
+#include <string_view>
+
#include "base/locks.h"
#include "obj_ptr.h"
@@ -31,7 +33,6 @@
class DexFile;
enum InvokeType : uint32_t;
class Signature;
-class StringPiece;
// AbstractMethodError
@@ -196,20 +197,20 @@
// NoSuchFieldError
-void ThrowNoSuchFieldError(const StringPiece& scope,
+void ThrowNoSuchFieldError(std::string_view scope,
ObjPtr<mirror::Class> c,
- const StringPiece& type,
- const StringPiece& name)
+ std::string_view type,
+ std::string_view name)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
-void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, const StringPiece& name)
+void ThrowNoSuchFieldException(ObjPtr<mirror::Class> c, std::string_view name)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
// NoSuchMethodError
void ThrowNoSuchMethodError(InvokeType type,
ObjPtr<mirror::Class> c,
- const StringPiece& name,
+ std::string_view name,
const Signature& signature)
REQUIRES_SHARED(Locks::mutator_lock_) COLD_ATTR;
diff --git a/runtime/interpreter/interpreter.cc b/runtime/interpreter/interpreter.cc
index 2e41a9d..aa11562 100644
--- a/runtime/interpreter/interpreter.cc
+++ b/runtime/interpreter/interpreter.cc
@@ -17,6 +17,7 @@
#include "interpreter.h"
#include <limits>
+#include <string_view>
#include "common_dex_operations.h"
#include "common_throws.h"
@@ -46,7 +47,7 @@
static void InterpreterJni(Thread* self,
ArtMethod* method,
- const StringPiece& shorty,
+ std::string_view shorty,
ObjPtr<mirror::Object> receiver,
uint32_t* args,
JValue* result)
diff --git a/runtime/jni/java_vm_ext.cc b/runtime/jni/java_vm_ext.cc
index e54b807..df96d28 100644
--- a/runtime/jni/java_vm_ext.cc
+++ b/runtime/jni/java_vm_ext.cc
@@ -17,6 +17,7 @@
#include "java_vm_ext.h"
#include <dlfcn.h>
+#include <string_view>
#include "android-base/stringprintf.h"
@@ -25,6 +26,7 @@
#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"
@@ -566,8 +568,8 @@
return false;
}
// Perform checks based on class name.
- StringPiece class_name(method->GetDeclaringClassDescriptor());
- if (!trace_.empty() && class_name.find(trace_) != std::string::npos) {
+ std::string_view class_name(method->GetDeclaringClassDescriptor());
+ if (!trace_.empty() && class_name.find(trace_) != std::string_view::npos) {
return true;
}
if (!VLOG_IS_ON(third_party_jni)) {
@@ -575,7 +577,7 @@
}
// Return true if we're trying to log all third-party JNI activity and 'method' doesn't look
// like part of Android.
- static const char* gBuiltInPrefixes[] = {
+ static const char* const gBuiltInPrefixes[] = {
"Landroid/",
"Lcom/android/",
"Lcom/google/android/",
@@ -586,7 +588,7 @@
"Lorg/apache/harmony/",
};
for (size_t i = 0; i < arraysize(gBuiltInPrefixes); ++i) {
- if (class_name.starts_with(gBuiltInPrefixes[i])) {
+ if (StartsWith(class_name, gBuiltInPrefixes[i])) {
return false;
}
}
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 6fd691f..f516d0d 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -24,7 +24,6 @@
#include "base/file_utils.h"
#include "base/macros.h"
-#include "base/stringpiece.h"
#include "base/utils.h"
#include "debugger.h"
#include "gc/heap.h"
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index feade83..97dccb0 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1173,8 +1173,8 @@
compiler_executable_ = runtime_options.ReleaseOrDefault(Opt::Compiler);
compiler_options_ = runtime_options.ReleaseOrDefault(Opt::CompilerOptions);
- for (StringPiece option : Runtime::Current()->GetCompilerOptions()) {
- if (option.starts_with("--debuggable")) {
+ for (const std::string& option : Runtime::Current()->GetCompilerOptions()) {
+ if (option == "--debuggable") {
SetJavaDebuggable(true);
break;
}
diff --git a/test/004-StackWalk/stack_walk_jni.cc b/test/004-StackWalk/stack_walk_jni.cc
index 81c27ec..6e53f30 100644
--- a/test/004-StackWalk/stack_walk_jni.cc
+++ b/test/004-StackWalk/stack_walk_jni.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <string_view>
+
#include "art_method-inl.h"
#include "check_reference_map_visitor.h"
#include "jni.h"
@@ -38,7 +40,7 @@
return true;
}
ArtMethod* m = GetMethod();
- StringPiece m_name(m->GetName());
+ std::string_view m_name(m->GetName());
// Given the method name and the number of times the method has been called,
// we know the Dex registers with live reference values. Assert that what we