Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Unified Diff: runtime/vm/object.cc

Issue 26072002: Rewrite Class::HasTypeArguments() for efficiency. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 28291)
+++ runtime/vm/object.cc (working copy)
@@ -1712,7 +1712,7 @@
Class& cls = Class::Handle(isolate);
TypeArguments& type_params = TypeArguments::Handle(isolate);
AbstractType& sup_type = AbstractType::Handle(isolate);
- cls ^= raw();
+ cls = raw();
intptr_t num_type_args = 0;
do {
@@ -1735,21 +1735,41 @@
cls.super_type() == isolate->object_store()->object_type()) {
break;
}
- sup_type ^= cls.super_type();
+ sup_type = cls.super_type();
cls = sup_type.type_class();
} while (true);
return num_type_args;
}
+// More efficient than calling NumTypeArguments().
bool Class::HasTypeArguments() const {
siva 2013/10/07 04:06:37 Would it make sense to have a fast check first: if
regis 2013/10/07 18:28:07 Done.
- if (!IsSignatureClass() && (is_finalized() || is_prefinalized())) {
- // More efficient than calling NumTypeArguments().
- return type_arguments_field_offset() != kNoTypeArguments;
- } else {
- // No need to check NumTypeArguments() if class has type parameters.
- return (NumTypeParameters() > 0) || (NumTypeArguments() > 0);
- }
+ Isolate* isolate = Isolate::Current();
+ Class& cls = Class::Handle(isolate);
+ cls = raw();
+ do {
+ if (!cls.IsSignatureClass() &&
+ (cls.is_finalized() || cls.is_prefinalized())) {
+ return cls.type_arguments_field_offset() != kNoTypeArguments;
+ }
+ if (cls.IsSignatureClass()) {
+ Function& signature_fun = Function::Handle(isolate);
+ signature_fun ^= cls.signature_function();
+ if (!signature_fun.is_static() &&
+ !signature_fun.HasInstantiatedSignature()) {
+ cls = signature_fun.Owner();
+ }
+ }
+ if (cls.NumTypeParameters() > 0) {
+ return true;
+ }
+ if ((cls.super_type() == AbstractType::null()) ||
+ (cls.super_type() == isolate->object_store()->object_type())) {
+ return false;
+ }
+ cls = cls.SuperClass();
+ } while (true);
+ UNREACHABLE();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698