зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1815558 - Clean up some MiscContainer string/atom usage, and optimize atom comparison on MiscContainer. r=smaug
Not sure if you think this is worth it, it might be in some cases where we have pre-atomized stuff in the container. Depends on D169142 Differential Revision: https://phabricator.services.mozilla.com/D169143
This commit is contained in:
Родитель
40c317a4de
Коммит
94dabce14e
|
@ -36,9 +36,6 @@
|
|||
|
||||
using namespace mozilla;
|
||||
|
||||
#define MISC_STR_PTR(_cont) \
|
||||
reinterpret_cast<void*>((_cont)->mStringBits & NS_ATTRVALUE_POINTERVALUE_MASK)
|
||||
|
||||
/* static */
|
||||
MiscContainer* nsAttrValue::AllocMiscContainer() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
@ -68,30 +65,17 @@ void nsAttrValue::DeallocMiscContainer(MiscContainer* aCont) {
|
|||
}
|
||||
|
||||
bool MiscContainer::GetString(nsAString& aString) const {
|
||||
void* ptr = MISC_STR_PTR(this);
|
||||
|
||||
bool isString;
|
||||
void* ptr = GetStringOrAtomPtr(isString);
|
||||
if (!ptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (static_cast<nsAttrValue::ValueBaseType>(mStringBits &
|
||||
NS_ATTRVALUE_BASETYPE_MASK) ==
|
||||
nsAttrValue::eStringBase) {
|
||||
nsStringBuffer* buffer = static_cast<nsStringBuffer*>(ptr);
|
||||
if (!buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isString) {
|
||||
auto* buffer = static_cast<nsStringBuffer*>(ptr);
|
||||
buffer->ToString(buffer->StorageSize() / sizeof(char16_t) - 1, aString);
|
||||
return true;
|
||||
} else {
|
||||
static_cast<nsAtom*>(ptr)->ToString(aString);
|
||||
}
|
||||
|
||||
nsAtom* atom = static_cast<nsAtom*>(ptr);
|
||||
if (!atom) {
|
||||
return false;
|
||||
}
|
||||
|
||||
atom->ToString(aString);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -326,10 +310,9 @@ void nsAttrValue::SetTo(const nsAttrValue& aOther) {
|
|||
}
|
||||
}
|
||||
|
||||
void* otherPtr = MISC_STR_PTR(otherCont);
|
||||
if (otherPtr) {
|
||||
if (static_cast<ValueBaseType>(otherCont->mStringBits &
|
||||
NS_ATTRVALUE_BASETYPE_MASK) == eStringBase) {
|
||||
bool isString;
|
||||
if (void* otherPtr = otherCont->GetStringOrAtomPtr(isString)) {
|
||||
if (isString) {
|
||||
static_cast<nsStringBuffer*>(otherPtr)->AddRef();
|
||||
} else {
|
||||
static_cast<nsAtom*>(otherPtr)->AddRef();
|
||||
|
@ -990,8 +973,7 @@ bool nsAttrValue::Equals(const nsAString& aValue,
|
|||
|
||||
bool nsAttrValue::Equals(const nsAtom* aValue,
|
||||
nsCaseTreatment aCaseSensitive) const {
|
||||
if (BaseType() == eAtomBase) {
|
||||
auto* atom = static_cast<nsAtom*>(GetPtr());
|
||||
if (auto* atom = GetStoredAtom()) {
|
||||
if (atom == aValue) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1334,6 +1316,26 @@ void nsAttrValue::SetDoubleValueAndType(double aValue, ValueType aType,
|
|||
SetMiscAtomOrString(aStringValue);
|
||||
}
|
||||
|
||||
nsAtom* nsAttrValue::GetStoredAtom() const {
|
||||
if (BaseType() == eAtomBase) {
|
||||
return static_cast<nsAtom*>(GetPtr());
|
||||
}
|
||||
if (BaseType() == eOtherBase) {
|
||||
return GetMiscContainer()->GetStoredAtom();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsStringBuffer* nsAttrValue::GetStoredStringBuffer() const {
|
||||
if (BaseType() == eStringBase) {
|
||||
return static_cast<nsStringBuffer*>(GetPtr());
|
||||
}
|
||||
if (BaseType() == eOtherBase) {
|
||||
return GetMiscContainer()->GetStoredStringBuffer();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int16_t nsAttrValue::GetEnumTableIndex(const EnumTable* aTable) {
|
||||
int16_t index = sEnumTableArray->IndexOf(aTable);
|
||||
if (index < 0) {
|
||||
|
@ -1826,10 +1828,9 @@ void nsAttrValue::SetMiscAtomOrString(const nsAString* aValue) {
|
|||
|
||||
void nsAttrValue::ResetMiscAtomOrString() {
|
||||
MiscContainer* cont = GetMiscContainer();
|
||||
void* ptr = MISC_STR_PTR(cont);
|
||||
if (ptr) {
|
||||
if (static_cast<ValueBaseType>(cont->mStringBits &
|
||||
NS_ATTRVALUE_BASETYPE_MASK) == eStringBase) {
|
||||
bool isString;
|
||||
if (void* ptr = cont->GetStringOrAtomPtr(isString)) {
|
||||
if (isString) {
|
||||
static_cast<nsStringBuffer*>(ptr)->Release();
|
||||
} else {
|
||||
static_cast<nsAtom*>(ptr)->Release();
|
||||
|
@ -1975,14 +1976,10 @@ size_t nsAttrValue::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
|
|||
}
|
||||
n += aMallocSizeOf(container);
|
||||
|
||||
void* otherPtr = MISC_STR_PTR(container);
|
||||
// We only count the size of the object pointed by otherPtr if it's a
|
||||
// string. When it's an atom, it's counted separatly.
|
||||
if (otherPtr && static_cast<ValueBaseType>(container->mStringBits &
|
||||
NS_ATTRVALUE_BASETYPE_MASK) ==
|
||||
eStringBase) {
|
||||
nsStringBuffer* str = static_cast<nsStringBuffer*>(otherPtr);
|
||||
n += str ? str->SizeOfIncludingThisIfUnshared(aMallocSizeOf) : 0;
|
||||
if (nsStringBuffer* buf = container->GetStoredStringBuffer()) {
|
||||
n += buf->SizeOfIncludingThisIfUnshared(aMallocSizeOf);
|
||||
}
|
||||
|
||||
if (Type() == eCSSDeclaration && container->mValue.mCSSDeclaration) {
|
||||
|
|
|
@ -509,6 +509,9 @@ class nsAttrValue {
|
|||
inline ValueBaseType BaseType() const;
|
||||
inline bool IsSVGType(ValueType aType) const;
|
||||
|
||||
nsAtom* GetStoredAtom() const;
|
||||
nsStringBuffer* GetStoredStringBuffer() const;
|
||||
|
||||
/**
|
||||
* Get the index of an EnumTable in the sEnumTableArray.
|
||||
* If the EnumTable is not in the sEnumTableArray, it is added.
|
||||
|
|
|
@ -89,6 +89,26 @@ struct MiscContainer final {
|
|||
public:
|
||||
bool GetString(nsAString& aString) const;
|
||||
|
||||
void* GetStringOrAtomPtr(bool& aIsString) const {
|
||||
uintptr_t bits = mStringBits;
|
||||
aIsString =
|
||||
nsAttrValue::ValueBaseType(mStringBits & NS_ATTRVALUE_BASETYPE_MASK) ==
|
||||
nsAttrValue::eStringBase;
|
||||
return reinterpret_cast<void*>(bits & NS_ATTRVALUE_POINTERVALUE_MASK);
|
||||
}
|
||||
|
||||
nsAtom* GetStoredAtom() const {
|
||||
bool isString = false;
|
||||
void* ptr = GetStringOrAtomPtr(isString);
|
||||
return isString ? nullptr : static_cast<nsAtom*>(ptr);
|
||||
}
|
||||
|
||||
nsStringBuffer* GetStoredStringBuffer() const {
|
||||
bool isString = false;
|
||||
void* ptr = GetStringOrAtomPtr(isString);
|
||||
return isString ? static_cast<nsStringBuffer*>(ptr) : nullptr;
|
||||
}
|
||||
|
||||
void SetStringBitsMainThread(uintptr_t aBits) {
|
||||
// mStringBits is atomic, but the callers of this function are
|
||||
// single-threaded so they don't have to worry about it.
|
||||
|
|
Загрузка…
Ссылка в новой задаче