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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 1705
1706 1706
1707 intptr_t Class::NumTypeArguments() const { 1707 intptr_t Class::NumTypeArguments() const {
1708 // To work properly, this call requires the super class of this class to be 1708 // To work properly, this call requires the super class of this class to be
1709 // resolved, which is checked by the type_class() call on the super type. 1709 // resolved, which is checked by the type_class() call on the super type.
1710 // Note that calling type_class() on a MixinAppType fails. 1710 // Note that calling type_class() on a MixinAppType fails.
1711 Isolate* isolate = Isolate::Current(); 1711 Isolate* isolate = Isolate::Current();
1712 Class& cls = Class::Handle(isolate); 1712 Class& cls = Class::Handle(isolate);
1713 TypeArguments& type_params = TypeArguments::Handle(isolate); 1713 TypeArguments& type_params = TypeArguments::Handle(isolate);
1714 AbstractType& sup_type = AbstractType::Handle(isolate); 1714 AbstractType& sup_type = AbstractType::Handle(isolate);
1715 cls ^= raw(); 1715 cls = raw();
1716 intptr_t num_type_args = 0; 1716 intptr_t num_type_args = 0;
1717 1717
1718 do { 1718 do {
1719 if (cls.IsSignatureClass()) { 1719 if (cls.IsSignatureClass()) {
1720 Function& signature_fun = Function::Handle(isolate); 1720 Function& signature_fun = Function::Handle(isolate);
1721 signature_fun ^= cls.signature_function(); 1721 signature_fun ^= cls.signature_function();
1722 if (!signature_fun.is_static() && 1722 if (!signature_fun.is_static() &&
1723 !signature_fun.HasInstantiatedSignature()) { 1723 !signature_fun.HasInstantiatedSignature()) {
1724 cls = signature_fun.Owner(); 1724 cls = signature_fun.Owner();
1725 } 1725 }
1726 } 1726 }
1727 // Calling NumTypeParameters() on a mixin application class will setup the 1727 // Calling NumTypeParameters() on a mixin application class will setup the
1728 // type parameters if not already done. 1728 // type parameters if not already done.
1729 if (cls.NumTypeParameters() > 0) { 1729 if (cls.NumTypeParameters() > 0) {
1730 type_params ^= cls.type_parameters(); 1730 type_params ^= cls.type_parameters();
1731 num_type_args += type_params.Length(); 1731 num_type_args += type_params.Length();
1732 } 1732 }
1733 // Super type of Object class is null. 1733 // Super type of Object class is null.
1734 if (cls.super_type() == AbstractType::null() || 1734 if (cls.super_type() == AbstractType::null() ||
1735 cls.super_type() == isolate->object_store()->object_type()) { 1735 cls.super_type() == isolate->object_store()->object_type()) {
1736 break; 1736 break;
1737 } 1737 }
1738 sup_type ^= cls.super_type(); 1738 sup_type = cls.super_type();
1739 cls = sup_type.type_class(); 1739 cls = sup_type.type_class();
1740 } while (true); 1740 } while (true);
1741 return num_type_args; 1741 return num_type_args;
1742 } 1742 }
1743 1743
1744 1744
1745 // More efficient than calling NumTypeArguments().
1745 bool Class::HasTypeArguments() const { 1746 bool Class::HasTypeArguments() const {
1747 // Fast check for a non-signature finalized class.
1746 if (!IsSignatureClass() && (is_finalized() || is_prefinalized())) { 1748 if (!IsSignatureClass() && (is_finalized() || is_prefinalized())) {
1747 // More efficient than calling NumTypeArguments().
1748 return type_arguments_field_offset() != kNoTypeArguments; 1749 return type_arguments_field_offset() != kNoTypeArguments;
1749 } else {
1750 // No need to check NumTypeArguments() if class has type parameters.
1751 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0);
1752 } 1750 }
1751 Isolate* isolate = Isolate::Current();
1752 Class& cls = Class::Handle(isolate);
1753 cls = raw();
1754 do {
1755 if (cls.IsSignatureClass()) {
1756 Function& signature_fun = Function::Handle(isolate);
1757 signature_fun ^= cls.signature_function();
1758 if (!signature_fun.is_static() &&
1759 !signature_fun.HasInstantiatedSignature()) {
1760 cls = signature_fun.Owner();
1761 }
1762 }
1763 if (cls.NumTypeParameters() > 0) {
1764 return true;
1765 }
1766 if ((cls.super_type() == AbstractType::null()) ||
1767 (cls.super_type() == isolate->object_store()->object_type())) {
1768 return false;
1769 }
1770 cls = cls.SuperClass();
1771 if (!cls.IsSignatureClass() &&
1772 (cls.is_finalized() || cls.is_prefinalized())) {
1773 return cls.type_arguments_field_offset() != kNoTypeArguments;
1774 }
1775 } while (true);
1776 UNREACHABLE();
1753 } 1777 }
1754 1778
1755 1779
1756 RawClass* Class::SuperClass() const { 1780 RawClass* Class::SuperClass() const {
1757 if (super_type() == AbstractType::null()) { 1781 if (super_type() == AbstractType::null()) {
1758 return Class::null(); 1782 return Class::null();
1759 } 1783 }
1760 const AbstractType& sup_type = AbstractType::Handle(super_type()); 1784 const AbstractType& sup_type = AbstractType::Handle(super_type());
1761 return sup_type.type_class(); 1785 return sup_type.type_class();
1762 } 1786 }
(...skipping 13553 matching lines...) Expand 10 before | Expand all | Expand 10 after
15316 return "_MirrorReference"; 15340 return "_MirrorReference";
15317 } 15341 }
15318 15342
15319 15343
15320 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15344 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15321 JSONObject jsobj(stream); 15345 JSONObject jsobj(stream);
15322 } 15346 }
15323 15347
15324 15348
15325 } // namespace dart 15349 } // namespace dart
OLDNEW
« 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