Backout changeset aec1ad4171a1 (bug 769504) because of merge conflicts with the rest of the backouts

This commit is contained in:
Ehsan Akhgari 2012-07-04 19:44:15 -04:00
parent c8900e25c1
commit c78cfe9cc2

View File

@ -644,9 +644,9 @@ class OrderedHashSet
bool bool
HashableValue::setValue(JSContext *cx, const Value &v) HashableValue::setValue(JSContext *cx, const Value &v)
{ {
if (v.isString()) { if (v.isString() && v.toString()->isRope()) {
// Atomize so that hash() and equals() are fast and infallible. // Flatten this rope so that equals() is infallible.
JSString *str = js_AtomizeString(cx, v.toString(), DoNotInternAtom); JSString *str = v.toString()->ensureLinear(cx);
if (!str) if (!str)
return false; return false;
value = StringValue(str); value = StringValue(str);
@ -676,15 +676,26 @@ HashableValue::hash() const
{ {
// HashableValue::setValue normalizes values so that the SameValue relation // HashableValue::setValue normalizes values so that the SameValue relation
// on HashableValues is the same as the == relationship on // on HashableValues is the same as the == relationship on
// value.data.asBits. // value.data.asBits, except for strings.
return value.asRawBits(); if (value.isString()) {
JSLinearString &s = value.toString()->asLinear();
return HashChars(s.chars(), s.length());
}
// Having dispensed with strings, we can just hash asBits.
uint64_t u = value.asRawBits();
return HashNumber((u >> 3) ^ (u >> (32 + 3)) ^ (u << (32 - 3)));
} }
bool bool
HashableValue::equals(const HashableValue &other) const HashableValue::equals(const HashableValue &other) const
{ {
// Two HashableValues are equal if they have equal bits. // Two HashableValues are equal if they have equal bits or they're equal strings.
bool b = (value.asRawBits() == other.value.asRawBits()); bool b = (value.asRawBits() == other.value.asRawBits()) ||
(value.isString() &&
other.value.isString() &&
EqualStrings(&value.toString()->asLinear(),
&other.value.toString()->asLinear()));
#ifdef DEBUG #ifdef DEBUG
bool same; bool same;