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

Side by Side Diff: runtime/lib/object.cc

Issue 2453463006: Revert "Revert "Recognize and optimize a.runtimeType == b.runtimeType pattern."" (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/lib/object_patch.dart » ('j') | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/code_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/heap.h" 10 #include "vm/heap.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 dart_arguments.SetAt(5, array); 109 dart_arguments.SetAt(5, array);
110 } 110 }
111 } 111 }
112 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); 112 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments);
113 return Object::null(); 113 return Object::null();
114 } 114 }
115 115
116 116
117 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) { 117 DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) {
118 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); 118 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
119 // Special handling for following types outside this native. 119 if (instance.IsString()) {
120 ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble()); 120 return Type::StringType();
121 } else if (instance.IsInteger()) {
122 return Type::IntType();
123 } else if (instance.IsDouble()) {
124 return Type::Double();
125 }
121 return instance.GetType(); 126 return instance.GetType();
122 } 127 }
123 128
124 129
130 DEFINE_NATIVE_ENTRY(Object_haveSameRuntimeType, 2) {
131 const Instance& left = Instance::CheckedHandle(arguments->NativeArgAt(0));
132 const Instance& right = Instance::CheckedHandle(arguments->NativeArgAt(1));
133
134 const intptr_t left_cid = left.GetClassId();
135 const intptr_t right_cid = right.GetClassId();
136
137 if (left_cid != right_cid) {
138 if (RawObject::IsIntegerClassId(left_cid)) {
139 return Bool::Get(RawObject::IsIntegerClassId(right_cid)).raw();
140 } else if (RawObject::IsStringClassId(right_cid)) {
141 return Bool::Get(RawObject::IsStringClassId(right_cid)).raw();
142 } else {
143 return Bool::False().raw();
144 }
145 }
146
147 const Class& cls = Class::Handle(left.clazz());
148 if (cls.IsClosureClass()) {
149 // TODO(vegorov): provide faster implementation for closure classes.
150 const AbstractType& left_type = AbstractType::Handle(left.GetType());
151 const AbstractType& right_type = AbstractType::Handle(right.GetType());
152 return Bool::Get(left_type.raw() == right_type.raw()).raw();
153 }
154
155 if (!cls.IsGeneric()) {
156 return Bool::True().raw();
157 }
158
159 const TypeArguments& left_type_arguments =
160 TypeArguments::Handle(left.GetTypeArguments());
161 const TypeArguments& right_type_arguments =
162 TypeArguments::Handle(right.GetTypeArguments());
163 return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw();
164 }
165
166
125 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) { 167 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) {
126 const Instance& instance = 168 const Instance& instance =
127 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 169 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
128 const TypeArguments& instantiator_type_arguments = 170 const TypeArguments& instantiator_type_arguments =
129 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); 171 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1));
130 const AbstractType& type = 172 const AbstractType& type =
131 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); 173 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2));
132 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3)); 174 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(3));
133 ASSERT(type.IsFinalized()); 175 ASSERT(type.IsFinalized());
134 ASSERT(!type.IsMalformed()); 176 ASSERT(!type.IsMalformed());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 405
364 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { 406 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) {
365 #if defined(ARCH_IS_64_BIT) 407 #if defined(ARCH_IS_64_BIT)
366 return Bool::True().raw(); 408 return Bool::True().raw();
367 #else 409 #else
368 return Bool::False().raw(); 410 return Bool::False().raw();
369 #endif // defined(ARCH_IS_64_BIT) 411 #endif // defined(ARCH_IS_64_BIT)
370 } 412 }
371 413
372 } // namespace dart 414 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/lib/object_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698