diff options
author | 2022-04-06 09:30:50 +0000 | |
---|---|---|
committer | 2024-11-05 15:24:05 +0000 | |
commit | 29ec7aef84f4b47d89edee274562b22a177b00b8 (patch) | |
tree | f958dafda289458ce7dac0ad86f7596636ee7ecf /runtime/native/dalvik_system_DexFile.cc | |
parent | 96dc77238e2b5a962911a6da06d5e1b869dc92f8 (diff) |
Use `std::string_view` for `ClassTable` operations.
Use `std::string_view` instead of `const char*` descriptor.
This uses faster `memcmp` instead of the slower`strcmp` for
descriptor comparison.
Note that the `ScopedTrace` passes `const char*` across the
`libartpalette` boundary, so we cannot easily replace the
`const char* descriptor` with `std::string_view descriptor`
in certain `ClassLinker` functions because we actually need
to pass a null-terminated string and the `string_view` API
does not technically guarantee null-terminated data.
Therefore we resort to explicitly passing around the
descriptor and its length as separate arguments.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Bug: 338123769
Change-Id: Ie3fa251390acc582c54b4686d18696eb89b32361
Diffstat (limited to 'runtime/native/dalvik_system_DexFile.cc')
-rw-r--r-- | runtime/native/dalvik_system_DexFile.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc index f7f446542c..a1d4f16d26 100644 --- a/runtime/native/dalvik_system_DexFile.cc +++ b/runtime/native/dalvik_system_DexFile.cc @@ -488,10 +488,9 @@ static jclass DexFile_defineClassNative(JNIEnv* env, return nullptr; } const std::string descriptor(DotToDescriptor(class_name.c_str())); - const size_t hash(ComputeModifiedUtf8Hash(descriptor.c_str())); + const size_t hash = ComputeModifiedUtf8Hash(descriptor); for (auto& dex_file : dex_files) { - const dex::ClassDef* dex_class_def = - OatDexFile::FindClassDef(*dex_file, descriptor.c_str(), hash); + const dex::ClassDef* dex_class_def = OatDexFile::FindClassDef(*dex_file, descriptor, hash); if (dex_class_def != nullptr) { ScopedObjectAccess soa(env); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); @@ -507,6 +506,7 @@ static jclass DexFile_defineClassNative(JNIEnv* env, } ObjPtr<mirror::Class> result = class_linker->DefineClass(soa.Self(), descriptor.c_str(), + descriptor.length(), hash, class_loader, *dex_file, |