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

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

Issue 10713008: Introduce a VM type cast to avoid repeating a type test and spare a handle. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | 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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 2424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 // is a subtype of V, or vice versa. We only return true if K == V, i.e. if 2435 // is a subtype of V, or vice versa. We only return true if K == V, i.e. if
2436 // they have the same index (both are finalized, so their indices are 2436 // they have the same index (both are finalized, so their indices are
2437 // comparable). 2437 // comparable).
2438 // The same rule applies When checking the upper bound of a still 2438 // The same rule applies When checking the upper bound of a still
2439 // uninstantiated type at compile time. Returning false will defer the test 2439 // uninstantiated type at compile time. Returning false will defer the test
2440 // to run time. But there are cases where it can be decided at compile time. 2440 // to run time. But there are cases where it can be decided at compile time.
2441 // For example, with class A<K, V extends K>, new A<T, T> called from within 2441 // For example, with class A<K, V extends K>, new A<T, T> called from within
2442 // a class B<T> will never require a run time bounds check, even it T is 2442 // a class B<T> will never require a run time bounds check, even it T is
2443 // uninstantiated at compile time. 2443 // uninstantiated at compile time.
2444 if (IsTypeParameter()) { 2444 if (IsTypeParameter()) {
2445 // TODO(regis): Introduce and use TypeParameter::Cast(). 2445 const TypeParameter* type_param = TypeParameter::Cast(*this);
Ivan Posva 2012/06/28 16:35:09 I am wondering if we will need a static const ob
regis 2012/06/28 18:44:51 Isn't it exactly what we have? That is, before I c
2446 const TypeParameter* type_param =
2447 reinterpret_cast<const TypeParameter*>(this);
2448 if (other.IsTypeParameter()) { 2446 if (other.IsTypeParameter()) {
2449 const TypeParameter* other_type_param = 2447 const TypeParameter* other_type_param =
2450 reinterpret_cast<const TypeParameter*>(&other); 2448 reinterpret_cast<const TypeParameter*>(&other);
2451 return type_param->index() == other_type_param->index(); 2449 return type_param->index() == other_type_param->index();
2452 } else if (FLAG_enable_type_checks) { 2450 } else if (FLAG_enable_type_checks) {
2453 // In checked mode, if the upper bound of this type is more specific than 2451 // In checked mode, if the upper bound of this type is more specific than
2454 // the other type, then this type is more specific than the other type. 2452 // the other type, then this type is more specific than the other type.
2455 const AbstractType& type_param_bound = 2453 const AbstractType& type_param_bound =
2456 AbstractType::Handle(type_param->bound()); 2454 AbstractType::Handle(type_param->bound());
2457 if (type_param_bound.IsMoreSpecificThan(other, malformed_error)) { 2455 if (type_param_bound.IsMoreSpecificThan(other, malformed_error)) {
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 3304
3307 bool TypeArguments::IsUninstantiatedIdentity() const { 3305 bool TypeArguments::IsUninstantiatedIdentity() const {
3308 ASSERT(!IsInstantiated()); 3306 ASSERT(!IsInstantiated());
3309 AbstractType& type = AbstractType::Handle(); 3307 AbstractType& type = AbstractType::Handle();
3310 intptr_t num_types = Length(); 3308 intptr_t num_types = Length();
3311 for (intptr_t i = 0; i < num_types; i++) { 3309 for (intptr_t i = 0; i < num_types; i++) {
3312 type = TypeAt(i); 3310 type = TypeAt(i);
3313 if (!type.IsTypeParameter()) { 3311 if (!type.IsTypeParameter()) {
3314 return false; 3312 return false;
3315 } 3313 }
3316 // TODO(regis): Introduce and use TypeParameter::Cast(). 3314 const TypeParameter* type_param = TypeParameter::Cast(type);
3317 TypeParameter* type_param = reinterpret_cast<TypeParameter*>(&type);
3318 if ((type_param->index() != i)) { 3315 if ((type_param->index() != i)) {
siva 2012/06/28 17:02:51 For example this would be const TypeParameter& typ
regis 2012/06/28 18:44:51 Done.
3319 return false; 3316 return false;
3320 } 3317 }
3321 } 3318 }
3322 return true; 3319 return true;
3323 } 3320 }
3324 3321
3325 3322
3326 RawAbstractTypeArguments* TypeArguments::InstantiateFrom( 3323 RawAbstractTypeArguments* TypeArguments::InstantiateFrom(
3327 const AbstractTypeArguments& instantiator_type_arguments) const { 3324 const AbstractTypeArguments& instantiator_type_arguments) const {
3328 ASSERT(!IsInstantiated()); 3325 ASSERT(!IsInstantiated());
(...skipping 3880 matching lines...) Expand 10 before | Expand all | Expand 10 after
7209 ASSERT(other.IsFinalized()); 7206 ASSERT(other.IsFinalized());
7210 ASSERT(!other.IsDynamicType()); 7207 ASSERT(!other.IsDynamicType());
7211 ASSERT(!other.IsVoidType()); 7208 ASSERT(!other.IsVoidType());
7212 ASSERT(!other.IsMalformed()); 7209 ASSERT(!other.IsMalformed());
7213 if (IsNull()) { 7210 if (IsNull()) {
7214 Class& other_class = Class::Handle(); 7211 Class& other_class = Class::Handle();
7215 if (other.IsTypeParameter()) { 7212 if (other.IsTypeParameter()) {
7216 if (other_instantiator.IsNull()) { 7213 if (other_instantiator.IsNull()) {
7217 return true; // Other type is uninstantiated, i.e. Dynamic. 7214 return true; // Other type is uninstantiated, i.e. Dynamic.
7218 } 7215 }
7219 // TODO(regis): Introduce and use TypeParameter::Cast(). 7216 const TypeParameter* other_type_param = TypeParameter::Cast(other);
7220 const TypeParameter* other_type_param =
7221 reinterpret_cast<const TypeParameter*>(&other);
7222 const AbstractType& instantiated_other = AbstractType::Handle( 7217 const AbstractType& instantiated_other = AbstractType::Handle(
7223 other_instantiator.TypeAt(other_type_param->index())); 7218 other_instantiator.TypeAt(other_type_param->index()));
7224 ASSERT(instantiated_other.IsInstantiated()); 7219 ASSERT(instantiated_other.IsInstantiated());
7225 other_class = instantiated_other.type_class(); 7220 other_class = instantiated_other.type_class();
7226 } else { 7221 } else {
7227 other_class = other.type_class(); 7222 other_class = other.type_class();
7228 } 7223 }
7229 return other_class.IsObjectClass() || other_class.IsDynamicClass(); 7224 return other_class.IsObjectClass() || other_class.IsDynamicClass();
7230 } 7225 }
7231 const Class& cls = Class::Handle(clazz()); 7226 const Class& cls = Class::Handle(clazz());
(...skipping 3040 matching lines...) Expand 10 before | Expand all | Expand 10 after
10272 const String& str = String::Handle(pattern()); 10267 const String& str = String::Handle(pattern());
10273 const char* format = "JSRegExp: pattern=%s flags=%s"; 10268 const char* format = "JSRegExp: pattern=%s flags=%s";
10274 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10269 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10275 char* chars = reinterpret_cast<char*>( 10270 char* chars = reinterpret_cast<char*>(
10276 Isolate::Current()->current_zone()->Allocate(len + 1)); 10271 Isolate::Current()->current_zone()->Allocate(len + 1));
10277 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10272 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10278 return chars; 10273 return chars;
10279 } 10274 }
10280 10275
10281 } // namespace dart 10276 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698