From 29ec7aef84f4b47d89edee274562b22a177b00b8 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 6 Apr 2022 09:30:50 +0000 Subject: 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 --- runtime/class_table.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'runtime/class_table.h') diff --git a/runtime/class_table.h b/runtime/class_table.h index 3374622f00..64ae758208 100644 --- a/runtime/class_table.h +++ b/runtime/class_table.h @@ -114,14 +114,15 @@ class ClassTable { static constexpr uint32_t kHashMask = kObjectAlignment - 1; }; - using DescriptorHashPair = std::pair; + using DescriptorHashPair = std::pair; class ClassDescriptorHash { public: // uint32_t for cross compilation. + // NO_THREAD_SAFETY_ANALYSIS: Used from unannotated `HashSet<>` functions. uint32_t operator()(const TableSlot& slot) const NO_THREAD_SAFETY_ANALYSIS; // uint32_t for cross compilation. - uint32_t operator()(const DescriptorHashPair& pair) const NO_THREAD_SAFETY_ANALYSIS; + uint32_t operator()(const DescriptorHashPair& pair) const; }; class ClassDescriptorEquals { @@ -221,7 +222,7 @@ class ClassTable { REQUIRES_SHARED(Locks::mutator_lock_); // Return the first class that matches the descriptor. Returns null if there are none. - ObjPtr Lookup(const char* descriptor, size_t hash) + ObjPtr Lookup(std::string_view descriptor, size_t hash) REQUIRES(!lock_) REQUIRES_SHARED(Locks::mutator_lock_); -- cgit v1.2.3-59-g8ed1b