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

Side by Side Diff: runtime/vm/object.h

Issue 2989493002: Simplify and fix implicit closure check, speed up Closure_equals (Closed)
Patch Set: Avoid overloaded NewClosureFunction Created 3 years, 5 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
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 #ifndef RUNTIME_VM_OBJECT_H_ 5 #ifndef RUNTIME_VM_OBJECT_H_
6 #define RUNTIME_VM_OBJECT_H_ 6 #define RUNTIME_VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2466 case RawFunction::kRegularFunction: 2466 case RawFunction::kRegularFunction:
2467 case RawFunction::kGetterFunction: 2467 case RawFunction::kGetterFunction:
2468 case RawFunction::kSetterFunction: 2468 case RawFunction::kSetterFunction:
2469 case RawFunction::kImplicitGetter: 2469 case RawFunction::kImplicitGetter:
2470 case RawFunction::kImplicitSetter: 2470 case RawFunction::kImplicitSetter:
2471 case RawFunction::kMethodExtractor: 2471 case RawFunction::kMethodExtractor:
2472 case RawFunction::kNoSuchMethodDispatcher: 2472 case RawFunction::kNoSuchMethodDispatcher:
2473 case RawFunction::kInvokeFieldDispatcher: 2473 case RawFunction::kInvokeFieldDispatcher:
2474 return true; 2474 return true;
2475 case RawFunction::kClosureFunction: 2475 case RawFunction::kClosureFunction:
2476 case RawFunction::kImplicitClosureFunction:
2476 case RawFunction::kSignatureFunction: 2477 case RawFunction::kSignatureFunction:
2477 case RawFunction::kConstructor: 2478 case RawFunction::kConstructor:
2478 case RawFunction::kImplicitStaticFinalGetter: 2479 case RawFunction::kImplicitStaticFinalGetter:
2479 case RawFunction::kIrregexpFunction: 2480 case RawFunction::kIrregexpFunction:
2480 return false; 2481 return false;
2481 default: 2482 default:
2482 UNREACHABLE(); 2483 UNREACHABLE();
2483 return false; 2484 return false;
2484 } 2485 }
2485 } 2486 }
2486 bool IsStaticFunction() const { 2487 bool IsStaticFunction() const {
2487 if (!is_static()) { 2488 if (!is_static()) {
2488 return false; 2489 return false;
2489 } 2490 }
2490 switch (kind()) { 2491 switch (kind()) {
2491 case RawFunction::kRegularFunction: 2492 case RawFunction::kRegularFunction:
2492 case RawFunction::kGetterFunction: 2493 case RawFunction::kGetterFunction:
2493 case RawFunction::kSetterFunction: 2494 case RawFunction::kSetterFunction:
2494 case RawFunction::kImplicitGetter: 2495 case RawFunction::kImplicitGetter:
2495 case RawFunction::kImplicitSetter: 2496 case RawFunction::kImplicitSetter:
2496 case RawFunction::kImplicitStaticFinalGetter: 2497 case RawFunction::kImplicitStaticFinalGetter:
2497 case RawFunction::kIrregexpFunction: 2498 case RawFunction::kIrregexpFunction:
2498 return true; 2499 return true;
2499 case RawFunction::kClosureFunction: 2500 case RawFunction::kClosureFunction:
2501 case RawFunction::kImplicitClosureFunction:
2500 case RawFunction::kSignatureFunction: 2502 case RawFunction::kSignatureFunction:
2501 case RawFunction::kConstructor: 2503 case RawFunction::kConstructor:
2502 case RawFunction::kMethodExtractor: 2504 case RawFunction::kMethodExtractor:
2503 case RawFunction::kNoSuchMethodDispatcher: 2505 case RawFunction::kNoSuchMethodDispatcher:
2504 case RawFunction::kInvokeFieldDispatcher: 2506 case RawFunction::kInvokeFieldDispatcher:
2505 return false; 2507 return false;
2506 default: 2508 default:
2507 UNREACHABLE(); 2509 UNREACHABLE();
2508 return false; 2510 return false;
2509 } 2511 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 } 2768 }
2767 2769
2768 // Returns true if this function represents an implicit setter function. 2770 // Returns true if this function represents an implicit setter function.
2769 bool IsImplicitSetterFunction() const { 2771 bool IsImplicitSetterFunction() const {
2770 return kind() == RawFunction::kImplicitSetter; 2772 return kind() == RawFunction::kImplicitSetter;
2771 } 2773 }
2772 2774
2773 // Returns true if this function represents a (possibly implicit) closure 2775 // Returns true if this function represents a (possibly implicit) closure
2774 // function. 2776 // function.
2775 bool IsClosureFunction() const { 2777 bool IsClosureFunction() const {
2776 return kind() == RawFunction::kClosureFunction; 2778 RawFunction::Kind k = kind();
2779 return (k == RawFunction::kClosureFunction) ||
2780 (k == RawFunction::kImplicitClosureFunction);
2777 } 2781 }
2778 2782
2779 // Returns true if this function represents a generated irregexp function. 2783 // Returns true if this function represents a generated irregexp function.
2780 bool IsIrregexpFunction() const { 2784 bool IsIrregexpFunction() const {
2781 return kind() == RawFunction::kIrregexpFunction; 2785 return kind() == RawFunction::kIrregexpFunction;
2782 } 2786 }
2783 2787
2784 // Returns true if this function represents an implicit closure function. 2788 // Returns true if this function represents an implicit closure function.
2785 bool IsImplicitClosureFunction() const; 2789 bool IsImplicitClosureFunction() const {
2790 return kind() == RawFunction::kImplicitClosureFunction;
2791 }
2786 2792
2787 // Returns true if this function represents a converted closure function. 2793 // Returns true if this function represents a converted closure function.
2788 bool IsConvertedClosureFunction() const { 2794 bool IsConvertedClosureFunction() const {
2789 return kind() == RawFunction::kConvertedClosureFunction; 2795 return kind() == RawFunction::kConvertedClosureFunction;
2790 } 2796 }
2791 2797
2792 // Returns true if this function represents a non implicit closure function. 2798 // Returns true if this function represents a non implicit closure function.
2793 bool IsNonImplicitClosureFunction() const { 2799 bool IsNonImplicitClosureFunction() const {
2794 return IsClosureFunction() && !IsImplicitClosureFunction(); 2800 return IsClosureFunction() && !IsImplicitClosureFunction();
2795 } 2801 }
2796 2802
2797 // Returns true if this function represents an implicit static closure 2803 // Returns true if this function represents an implicit static closure
2798 // function. 2804 // function.
2799 bool IsImplicitStaticClosureFunction() const { 2805 bool IsImplicitStaticClosureFunction() const {
2800 return is_static() && IsImplicitClosureFunction(); 2806 return IsImplicitClosureFunction() && is_static();
2801 } 2807 }
2802 static bool IsImplicitStaticClosureFunction(RawFunction* func); 2808 static bool IsImplicitStaticClosureFunction(RawFunction* func);
2803 2809
2804 // Returns true if this function represents an implicit instance closure 2810 // Returns true if this function represents an implicit instance closure
2805 // function. 2811 // function.
2806 bool IsImplicitInstanceClosureFunction() const { 2812 bool IsImplicitInstanceClosureFunction() const {
2807 return !is_static() && IsImplicitClosureFunction(); 2813 return IsImplicitClosureFunction() && !is_static();
2808 } 2814 }
2809 2815
2810 bool IsConstructorClosureFunction() const; 2816 bool IsConstructorClosureFunction() const;
2811 2817
2812 // Returns true if this function represents a local function. 2818 // Returns true if this function represents a local function.
2813 bool IsLocalFunction() const { return parent_function() != Function::null(); } 2819 bool IsLocalFunction() const { return parent_function() != Function::null(); }
2814 2820
2815 // Returns true if this function represents a signature function without code. 2821 // Returns true if this function represents a signature function without code.
2816 bool IsSignatureFunction() const { 2822 bool IsSignatureFunction() const {
2817 return kind() == RawFunction::kSignatureFunction; 2823 return kind() == RawFunction::kSignatureFunction;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2869 RawFunction::Kind kind, 2875 RawFunction::Kind kind,
2870 bool is_static, 2876 bool is_static,
2871 bool is_const, 2877 bool is_const,
2872 bool is_abstract, 2878 bool is_abstract,
2873 bool is_external, 2879 bool is_external,
2874 bool is_native, 2880 bool is_native,
2875 const Object& owner, 2881 const Object& owner,
2876 TokenPosition token_pos, 2882 TokenPosition token_pos,
2877 Heap::Space space = Heap::kOld); 2883 Heap::Space space = Heap::kOld);
2878 2884
2885 // Allocates a new Function object representing a closure function
2886 // with given kind - kClosureFunction, kImplicitClosureFunction or
2887 // kConvertedClosureFunction.
2888 static RawFunction* NewClosureFunctionWithKind(RawFunction::Kind kind,
2889 const String& name,
2890 const Function& parent,
2891 TokenPosition token_pos);
2892
2879 // Allocates a new Function object representing a closure function. 2893 // Allocates a new Function object representing a closure function.
2880 static RawFunction* NewClosureFunction(const String& name, 2894 static RawFunction* NewClosureFunction(const String& name,
2881 const Function& parent, 2895 const Function& parent,
2882 TokenPosition token_pos); 2896 TokenPosition token_pos);
2883 2897
2898 // Allocates a new Function object representing an implicit closure function.
2899 static RawFunction* NewImplicitClosureFunction(const String& name,
2900 const Function& parent,
2901 TokenPosition token_pos);
2902
2884 // Allocates a new Function object representing a converted closure function. 2903 // Allocates a new Function object representing a converted closure function.
2885 static RawFunction* NewConvertedClosureFunction(const String& name, 2904 static RawFunction* NewConvertedClosureFunction(const String& name,
2886 const Function& parent, 2905 const Function& parent,
2887 TokenPosition token_pos); 2906 TokenPosition token_pos);
2888 2907
2889 // Allocates a new Function object representing a signature function. 2908 // Allocates a new Function object representing a signature function.
2890 // The owner is the scope class of the function type. 2909 // The owner is the scope class of the function type.
2891 // The parent is the enclosing function or null if none. 2910 // The parent is the enclosing function or null if none.
2892 static RawFunction* NewSignatureFunction(const Object& owner, 2911 static RawFunction* NewSignatureFunction(const Object& owner,
2893 const Function& parent, 2912 const Function& parent,
(...skipping 6072 matching lines...) Expand 10 before | Expand all | Expand 10 after
8966 8985
8967 inline void TypeArguments::SetHash(intptr_t value) const { 8986 inline void TypeArguments::SetHash(intptr_t value) const {
8968 // This is only safe because we create a new Smi, which does not cause 8987 // This is only safe because we create a new Smi, which does not cause
8969 // heap allocation. 8988 // heap allocation.
8970 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 8989 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8971 } 8990 }
8972 8991
8973 } // namespace dart 8992 } // namespace dart
8974 8993
8975 #endif // RUNTIME_VM_OBJECT_H_ 8994 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698