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

Unified Diff: runtime/lib/object.cc

Issue 2379733002: Recognize and optimize a.runtimeType == b.runtimeType pattern. (Closed)
Patch Set: fix lint Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/lib/object_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/object.cc
diff --git a/runtime/lib/object.cc b/runtime/lib/object.cc
index e1b7a71c8eb53bfc7acd3a25760dcfbd6a5940a6..530b2107f47935b2622909def56db1f0196104d2 100644
--- a/runtime/lib/object.cc
+++ b/runtime/lib/object.cc
@@ -116,12 +116,54 @@ DEFINE_NATIVE_ENTRY(Object_noSuchMethod, 6) {
DEFINE_NATIVE_ENTRY(Object_runtimeType, 1) {
const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0));
- // Special handling for following types outside this native.
- ASSERT(!instance.IsString() && !instance.IsInteger() && !instance.IsDouble());
+ if (instance.IsString()) {
+ return Type::StringType();
+ } else if (instance.IsInteger()) {
+ return Type::IntType();
+ } else if (instance.IsDouble()) {
+ return Type::Double();
+ }
return instance.GetType();
}
+DEFINE_NATIVE_ENTRY(Object_haveSameRuntimeType, 2) {
+ const Instance& left = Instance::CheckedHandle(arguments->NativeArgAt(0));
+ const Instance& right = Instance::CheckedHandle(arguments->NativeArgAt(1));
+
+ const intptr_t left_cid = left.GetClassId();
+ const intptr_t right_cid = right.GetClassId();
+
+ if (left_cid != right_cid) {
+ if (RawObject::IsIntegerClassId(left_cid)) {
+ return Bool::Get(RawObject::IsIntegerClassId(right_cid)).raw();
+ } else if (RawObject::IsStringClassId(right_cid)) {
+ return Bool::Get(RawObject::IsStringClassId(right_cid)).raw();
+ } else {
+ return Bool::False().raw();
+ }
+ }
+
+ const Class& cls = Class::Handle(left.clazz());
+ if (cls.IsClosureClass()) {
+ // TODO(vegorov): provide faster implementation for closure classes.
+ const AbstractType& left_type = AbstractType::Handle(left.GetType());
+ const AbstractType& right_type = AbstractType::Handle(right.GetType());
+ return Bool::Get(left_type.raw() == right_type.raw()).raw();
+ }
+
+ if (!cls.IsGeneric()) {
+ return Bool::True().raw();
+ }
+
+ const TypeArguments& left_type_arguments =
+ TypeArguments::Handle(left.GetTypeArguments());
+ const TypeArguments& right_type_arguments =
+ TypeArguments::Handle(right.GetTypeArguments());
+ return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw();
+}
+
+
DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) {
const Instance& instance =
Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
« 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