Streamline ClassHelper::GetDescriptor
This hot method has a lot of corner cases, try to aid the compiler in
optimizing for the common case.
Change-Id: I78df837eddd3b2475bdc1afdbbd7395bce8c44f7
diff --git a/src/object_utils.h b/src/object_utils.h
index 42937cf..f9aca10 100644
--- a/src/object_utils.h
+++ b/src/object_utils.h
@@ -57,17 +57,11 @@
// The returned const char* is only guaranteed to be valid for the lifetime of the ClassHelper.
// If you need it longer, copy it into a std::string.
const char* GetDescriptor() {
- if (klass_->IsArrayClass()) {
- std::string result("[");
- const Class* saved_klass = klass_;
- ChangeClass(klass_->GetComponentType());
- result += GetDescriptor();
- ChangeClass(saved_klass);
- descriptor_ = result;
- return descriptor_.c_str();
- } else if (klass_->IsPrimitive()) {
+ if (UNLIKELY(klass_->IsArrayClass())) {
+ return GetArrayDescriptor();
+ } else if (UNLIKELY(klass_->IsPrimitive())) {
return Primitive::Descriptor(klass_->GetPrimitiveType());
- } else if (klass_->IsProxyClass()) {
+ } else if (UNLIKELY(klass_->IsProxyClass())) {
descriptor_ = GetClassLinker()->GetDescriptorForProxy(klass_);
return descriptor_.c_str();
} else {
@@ -77,6 +71,16 @@
}
}
+ const char* GetArrayDescriptor() {
+ std::string result("[");
+ const Class* saved_klass = klass_;
+ ChangeClass(klass_->GetComponentType());
+ result += GetDescriptor();
+ ChangeClass(saved_klass);
+ descriptor_ = result;
+ return descriptor_.c_str();
+ }
+
const DexFile::ClassDef* GetClassDef() {
const DexFile::ClassDef* result = class_def_;
if (result == NULL) {