Faster hashing in `ClassLinker::LinkVirtualMethods()`.
Measurement shows that `ComputeModifiedUtf8Hash()` is faster
when iterating over `std::string_view` than `const char*`.
However, getting the length of the string with `strlen()`
would outweigh the benefits, so we shall only use the new
`ComputeModifiedUtf8Hash(std::string_view)` overload when
we can avoid (or usually avoid) the `strlen()` call.
In `ClassLinker::LinkVirtualMethods()`, method names come
from the dex file and we can avoid the `strlen()` call as
long as they are ASCII which is usually the case (at least
for boot class path methods; proguarded apps sometimes use
non-ASCII method names), so use `std::string_view` there.
Also simplify the code a bit, avoiding the UTF16 length
comparison. This has some trade-offs as we delay the length
comparison until we know the length in chars (and compare
that length instead) but we also replace `strcmp()` with a
faster `memcmp()`.
The changes to the Modified UTF-8 hashing API also prepare
for future work such as calculating array class descriptor
hash without a string allocation for the full descriptor.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 181943478
Change-Id: I6d45f738903000c55d401b776906dac83fca1a19
3 files changed