hiddenapi: Use std::string_view more.
Using std::string_view instead of std::string avoids a lot
of unnecessary allocations. The time to process the boot
classpath for aosp_taimen-userdebug goes from ~9s to ~6s.
Test: m
Change-Id: I102763a1862cd917cd136b827f66f3d7d93800e3
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index 141dd22..d810a64 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -113,12 +113,12 @@
bool HasSuperclass() const { return dex_file_.IsTypeIndexValid(GetSuperclassIndex()); }
- std::string GetSuperclassDescriptor() const {
+ std::string_view GetSuperclassDescriptor() const {
return HasSuperclass() ? dex_file_.StringByTypeIdx(GetSuperclassIndex()) : "";
}
- std::set<std::string> GetInterfaceDescriptors() const {
- std::set<std::string> list;
+ std::set<std::string_view> GetInterfaceDescriptors() const {
+ std::set<std::string_view> list;
const dex::TypeList* ifaces = dex_file_.GetInterfacesList(GetClassDef());
for (uint32_t i = 0; ifaces != nullptr && i < ifaces->Size(); ++i) {
list.insert(dex_file_.StringByTypeIdx(ifaces->GetTypeItem(i).type_idx_));
@@ -156,7 +156,7 @@
uint32_t GetAccessFlags() const { return GetClassDef().access_flags_; }
bool HasAccessFlags(uint32_t mask) const { return (GetAccessFlags() & mask) == mask; }
- static std::string JoinStringSet(const std::set<std::string>& s) {
+ static std::string JoinStringSet(const std::set<std::string_view>& s) {
return "{" + ::android::base::Join(std::vector<std::string>(s.begin(), s.end()), ",") + "}";
}
};
@@ -209,7 +209,7 @@
inline uint32_t GetAccessFlags() const { return item_.GetAccessFlags(); }
inline uint32_t HasAccessFlags(uint32_t mask) const { return (GetAccessFlags() & mask) == mask; }
- inline std::string GetName() const {
+ inline std::string_view GetName() const {
return IsMethod() ? item_.GetDexFile().GetMethodName(GetMethodId())
: item_.GetDexFile().GetFieldName(GetFieldId());
}
@@ -508,7 +508,7 @@
}
private:
- HierarchyClass* FindClass(const std::string& descriptor) {
+ HierarchyClass* FindClass(const std::string_view& descriptor) {
auto it = classes_.find(descriptor);
if (it == classes_.end()) {
return nullptr;
@@ -539,7 +539,7 @@
CHECK(superclass != nullptr);
klass.AddExtends(*superclass);
- for (const std::string& iface_desc : dex_klass.GetInterfaceDescriptors()) {
+ for (const std::string_view& iface_desc : dex_klass.GetInterfaceDescriptors()) {
HierarchyClass* iface = FindClass(iface_desc);
CHECK(iface != nullptr);
klass.AddExtends(*iface);
@@ -548,7 +548,7 @@
}
ClassPath& classpath_;
- std::map<std::string, HierarchyClass> classes_;
+ std::map<std::string_view, HierarchyClass> classes_;
};
// Builder of dex section containing hiddenapi flags.