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

Unified Diff: src/objects.cc

Issue 299703004: Use SameValueZero for Map and Set (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 | « src/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 8e8830a768522103da2f79173b33d174e3150664..a1ca34ead8dc83ec02d448eeb23d0953409df07a 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -975,6 +975,25 @@ bool Object::SameValue(Object* other) {
}
+bool Object::SameValueZero(Object* other) {
+ if (other == this) return true;
+
+ // The object is either a number, a name, an odd-ball,
+ // a real JS object, or a Harmony proxy.
+ if (IsNumber() && other->IsNumber()) {
+ double this_value = Number();
+ double other_value = other->Number();
+ // +0 == -0 is true
+ return this_value == other_value
+ || (std::isnan(this_value) && std::isnan(other_value));
+ }
+ if (IsString() && other->IsString()) {
+ return String::cast(this)->Equals(String::cast(other));
+ }
+ return false;
+}
+
+
void Object::ShortPrint(FILE* out) {
HeapStringAllocator allocator;
StringStream accumulator(&allocator);
@@ -16329,7 +16348,7 @@ int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry(
entry != kNotFound;
entry = ChainAt(entry)) {
Object* candidate = KeyAt(entry);
- if (candidate->SameValue(*key))
+ if (candidate->SameValueZero(*key))
return entry;
}
return kNotFound;
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698