Bug 1362338: Take a bit from the atom's length to store a tristate. r=froydnj

MozReview-Commit-ID: Elu9EioSDXk
This commit is contained in:
Emilio Cobos Álvarez 2017-08-09 14:19:30 +02:00
Родитель a7d696a18f
Коммит e99fdbe52e
3 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -9,7 +9,7 @@
nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
{
mLength = aString.Length();
mIsStatic = false;
SetKind(AtomKind::HTML5Atom);
RefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
if (buf) {
mString = static_cast<char16_t*>(buf->Data());

Просмотреть файл

@ -93,7 +93,7 @@ private:
: mRefCnt(1)
{
mLength = aString.Length();
mIsStatic = false;
SetKind(AtomKind::DynamicAtom);
RefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
if (buf) {
mString = static_cast<char16_t*>(buf->Data());
@ -171,7 +171,7 @@ public:
StaticAtom(nsStringBuffer* aStringBuffer, uint32_t aLength, uint32_t aHash)
{
mLength = aLength;
mIsStatic = true;
SetKind(AtomKind::StaticAtom);
mString = static_cast<char16_t*>(aStringBuffer->Data());
#if defined(NS_BUILD_REFCNT_LOGGING)

Просмотреть файл

@ -37,6 +37,14 @@ interface nsIAtom : nsISupports
size_t SizeOfIncludingThis(in MallocSizeOf aMallocSizeOf);
%{C++
// The kind of atom we have, in order to be able to devirtualize hot stuff
// looking at mKind.
enum class AtomKind : uint8_t {
DynamicAtom = 0,
StaticAtom = 1,
HTML5Atom = 2,
};
// note these are NOT virtual so they won't muck with the vtable!
inline bool Equals(char16ptr_t aString, uint32_t aLength) const
{
@ -48,8 +56,25 @@ interface nsIAtom : nsISupports
return Equals(aString.BeginReading(), aString.Length());
}
inline void SetKind(AtomKind aKind) {
mKind = static_cast<uint32_t>(aKind);
MOZ_ASSERT(Kind() == aKind);
}
inline AtomKind Kind() const {
return static_cast<AtomKind>(mKind);
}
inline bool IsDynamicAtom() const {
return Kind() == AtomKind::DynamicAtom;
}
inline bool IsHTML5Atom() const {
return Kind() == AtomKind::HTML5Atom;
}
inline bool IsStaticAtom() const {
return mIsStatic;
return Kind() == AtomKind::StaticAtom;
}
inline char16ptr_t GetUTF16String() const {
@ -80,8 +105,8 @@ interface nsIAtom : nsISupports
}
protected:
uint32_t mLength:31;
uint32_t mIsStatic:1;
uint32_t mLength: 30;
uint32_t mKind: 2; // nsIAtom::AtomKind
uint32_t mHash;
/**
* WARNING! There is an invisible constraint on |mString|: the chars it