diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index 11e4e72cc874..597b6223ed6e 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -960,8 +960,7 @@ bool nsAttrValue::Equals(const nsAString& aValue, nsCaseTreatment aCaseSensitive) const { switch (BaseType()) { case eStringBase: { - nsStringBuffer* str = static_cast(GetPtr()); - if (str) { + if (auto* str = static_cast(GetPtr())) { nsDependentString dep(static_cast(str->Data()), str->StorageSize() / sizeof(char16_t) - 1); return aCaseSensitive == eCaseMatters @@ -970,12 +969,14 @@ bool nsAttrValue::Equals(const nsAString& aValue, } return aValue.IsEmpty(); } - case eAtomBase: + case eAtomBase: { + auto* atom = static_cast(GetPtr()); if (aCaseSensitive == eCaseMatters) { - return static_cast(GetPtr())->Equals(aValue); + return atom->Equals(aValue); } - return nsContentUtils::EqualsIgnoreASCIICase( - nsDependentAtomString(static_cast(GetPtr())), aValue); + return nsContentUtils::EqualsIgnoreASCIICase(nsDependentAtomString(atom), + aValue); + } default: break; } @@ -989,33 +990,19 @@ bool nsAttrValue::Equals(const nsAString& aValue, bool nsAttrValue::Equals(const nsAtom* aValue, nsCaseTreatment aCaseSensitive) const { - if (aCaseSensitive != eCaseMatters) { - // Need a better way to handle this! - nsAutoString value; - aValue->ToString(value); - return Equals(value, aCaseSensitive); - } - - switch (BaseType()) { - case eStringBase: { - nsStringBuffer* str = static_cast(GetPtr()); - if (str) { - nsDependentString dep(static_cast(str->Data()), - str->StorageSize() / sizeof(char16_t) - 1); - return aValue->Equals(dep); - } - return aValue == nsGkAtoms::_empty; + if (BaseType() == eAtomBase) { + auto* atom = static_cast(GetPtr()); + if (atom == aValue) { + return true; } - case eAtomBase: { - return static_cast(GetPtr()) == aValue; + if (aCaseSensitive == eCaseMatters) { + return false; + } + if (atom->IsAsciiLowercase() && aValue->IsAsciiLowercase()) { + return false; } - default: - break; } - - nsAutoString val; - ToString(val); - return aValue->Equals(val); + return Equals(nsDependentAtomString(aValue), aCaseSensitive); } struct HasPrefixFn {