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

Unified Diff: runtime/lib/identical.cc

Issue 11613003: Implement a native identical function in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix comment, use plain vanilla numbers in the test instead of the .pow function Created 8 years 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 | « no previous file | runtime/lib/identical_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/identical.cc
diff --git a/runtime/lib/identical.cc b/runtime/lib/identical.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4c452e0299e542fe6a492c8a10aec1c521c14057
--- /dev/null
+++ b/runtime/lib/identical.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/bootstrap_natives.h"
+
+#include "vm/object.h"
+
+namespace dart {
+
+DEFINE_NATIVE_ENTRY(Identical_comparison, 2) {
+ GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
+ GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1));
+ if (a.raw() == b.raw()) return Bool::True();
+ if (a.IsInteger() && b.IsInteger()) {
+ return Bool::Get(a.Equals(b));
+ }
+ if (a.IsDouble() && b.IsDouble()) {
+ if (a.Equals(b)) return Bool::True();
+ // Check for NaN.
+ const Double& a_double = Double::Cast(a);
+ const Double& b_double = Double::Cast(b);
+ if (isnan(a_double.value()) && isnan(b_double.value())) {
+ return Bool::True();
+ }
+ }
+ return Bool::False();
+}
+
+
+} // namespace dart
« no previous file with comments | « no previous file | runtime/lib/identical_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698