Bug 984761 - Add AttributeMap::operator==. r=roc

This commit is contained in:
Markus Stange 2014-03-20 10:12:44 +08:00
parent 55cc3adae6
commit 46966112cf
2 changed files with 40 additions and 0 deletions

View File

@ -1783,6 +1783,41 @@ AttributeMap::operator=(const AttributeMap& aOther)
return *this;
}
namespace {
struct MatchingMap {
typedef nsClassHashtable<nsUint32HashKey, Attribute> Map;
const Map& map;
bool matches;
};
}
static PLDHashOperator
CheckAttributeEquality(const uint32_t& aAttributeName,
Attribute* aAttribute,
void* aMatchingMap)
{
MatchingMap& matchingMap = *static_cast<MatchingMap*>(aMatchingMap);
Attribute* matchingAttribute = matchingMap.map.Get(aAttributeName);
if (!matchingAttribute ||
*matchingAttribute != *aAttribute) {
matchingMap.matches = false;
return PL_DHASH_STOP;
}
return PL_DHASH_NEXT;
}
bool
AttributeMap::operator==(const AttributeMap& aOther) const
{
if (mMap.Count() != aOther.mMap.Count()) {
return false;
}
MatchingMap matchingMap = { mMap, true };
aOther.mMap.EnumerateRead(CheckAttributeEquality, &matchingMap);
return matchingMap.matches;
}
#define MAKE_ATTRIBUTE_HANDLERS_BASIC(type, typeLabel, defaultValue) \
type \
AttributeMap::Get##typeLabel(AttributeName aName) const { \

View File

@ -173,6 +173,11 @@ public:
AttributeMap();
AttributeMap(const AttributeMap& aOther);
AttributeMap& operator=(const AttributeMap& aOther);
bool operator==(const AttributeMap& aOther) const;
bool operator!=(const AttributeMap& aOther) const
{
return !(*this == aOther);
}
~AttributeMap();
void Set(AttributeName aName, bool aValue);