diff options
| -rw-r--r-- | runtime/dex_file.cc | 26 | ||||
| -rw-r--r-- | runtime/dex_file.h | 5 |
2 files changed, 27 insertions, 4 deletions
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc index a7575ce889..517f96c623 100644 --- a/runtime/dex_file.cc +++ b/runtime/dex_file.cc @@ -876,6 +876,32 @@ std::string Signature::ToString() const { return result; } +bool Signature::operator==(const StringPiece& rhs) const { + if (dex_file_ == nullptr) { + return false; + } + StringPiece tail(rhs); + if (!tail.starts_with("(")) { + return false; // Invalid signature + } + tail.remove_prefix(1); // "("; + const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_); + if (params != nullptr) { + for (uint32_t i = 0; i < params->Size(); ++i) { + StringPiece param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_)); + if (!tail.starts_with(param)) { + return false; + } + tail.remove_prefix(param.length()); + } + } + if (!tail.starts_with(")")) { + return false; + } + tail.remove_prefix(1); // ")"; + return tail == dex_file_->StringByTypeIdx(proto_id_->return_type_idx_); +} + std::ostream& operator<<(std::ostream& os, const Signature& sig) { return os << sig.ToString(); } diff --git a/runtime/dex_file.h b/runtime/dex_file.h index 84026a46e6..69593cdffc 100644 --- a/runtime/dex_file.h +++ b/runtime/dex_file.h @@ -964,10 +964,7 @@ class Signature { return !(*this == rhs); } - bool operator==(const StringPiece& rhs) const { - // TODO: Avoid temporary string allocation. - return ToString() == rhs; - } + bool operator==(const StringPiece& rhs) const; private: Signature(const DexFile* dex, const DexFile::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) { |