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

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

Issue 1222863003: Make frequent type checks (instanceof) faster by adding dedicated instanceof methods; improves dart… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: flag Created 5 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
« no previous file with comments | « no previous file | 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 zone, String::New(bound_error.ToErrorCString())); 200 zone, String::New(bound_error.ToErrorCString()));
201 Exceptions::CreateAndThrowTypeError( 201 Exceptions::CreateAndThrowTypeError(
202 location, Symbols::Empty(), Symbols::Empty(), 202 location, Symbols::Empty(), Symbols::Empty(),
203 Symbols::Empty(), bound_error_message); 203 Symbols::Empty(), bound_error_message);
204 UNREACHABLE(); 204 UNREACHABLE();
205 } 205 }
206 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw(); 206 return Bool::Get(negate.value() ? !is_instance_of : is_instance_of).raw();
207 } 207 }
208 208
209 209
210 DEFINE_NATIVE_ENTRY(Object_instanceOfNum, 2) {
211 const Instance& instance =
212 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
213 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1));
214 bool is_instance_of = instance.IsNumber();
215 if (negate.value()) {
216 is_instance_of = !is_instance_of;
217 }
218 return Bool::Get(is_instance_of).raw();
219 }
220
221
222 DEFINE_NATIVE_ENTRY(Object_instanceOfInt, 2) {
223 const Instance& instance =
224 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
225 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1));
226 bool is_instance_of = instance.IsInteger();
227 if (negate.value()) {
228 is_instance_of = !is_instance_of;
229 }
230 return Bool::Get(is_instance_of).raw();
231 }
232
233
234 DEFINE_NATIVE_ENTRY(Object_instanceOfSmi, 2) {
235 const Instance& instance =
236 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
237 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1));
238 bool is_instance_of = instance.IsSmi();
239 if (negate.value()) {
240 is_instance_of = !is_instance_of;
241 }
242 return Bool::Get(is_instance_of).raw();
243 }
244
245
246 DEFINE_NATIVE_ENTRY(Object_instanceOfDouble, 2) {
247 const Instance& instance =
248 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
249 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1));
250 bool is_instance_of = instance.IsDouble();
251 if (negate.value()) {
252 is_instance_of = !is_instance_of;
253 }
254 return Bool::Get(is_instance_of).raw();
255 }
256
257
258 DEFINE_NATIVE_ENTRY(Object_instanceOfString, 2) {
259 const Instance& instance =
260 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
261 const Bool& negate = Bool::CheckedHandle(zone, arguments->NativeArgAt(1));
262 bool is_instance_of = instance.IsString();
263 if (negate.value()) {
264 is_instance_of = !is_instance_of;
265 }
266 return Bool::Get(is_instance_of).raw();
267 }
268
269
210 DEFINE_NATIVE_ENTRY(Object_as, 4) { 270 DEFINE_NATIVE_ENTRY(Object_as, 4) {
211 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); 271 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
212 // Instantiator at position 1 is not used. It is passed along so that the call 272 // Instantiator at position 1 is not used. It is passed along so that the call
213 // can be easily converted to an optimized implementation. Instantiator is 273 // can be easily converted to an optimized implementation. Instantiator is
214 // used to populate the subtype cache. 274 // used to populate the subtype cache.
215 const TypeArguments& instantiator_type_arguments = 275 const TypeArguments& instantiator_type_arguments =
216 TypeArguments::CheckedHandle(arguments->NativeArgAt(2)); 276 TypeArguments::CheckedHandle(arguments->NativeArgAt(2));
217 const AbstractType& type = 277 const AbstractType& type =
218 AbstractType::CheckedHandle(arguments->NativeArgAt(3)); 278 AbstractType::CheckedHandle(arguments->NativeArgAt(3));
219 ASSERT(type.IsFinalized()); 279 ASSERT(type.IsFinalized());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 380
321 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { 381 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) {
322 #if defined(ARCH_IS_64_BIT) 382 #if defined(ARCH_IS_64_BIT)
323 return Bool::True().raw(); 383 return Bool::True().raw();
324 #else 384 #else
325 return Bool::False().raw(); 385 return Bool::False().raw();
326 #endif // defined(ARCH_IS_64_BIT) 386 #endif // defined(ARCH_IS_64_BIT)
327 } 387 }
328 388
329 } // namespace dart 389 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/object_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698