Skip to content

Commit

Permalink
Bug 1401873 - Remove nsHtml5Atom. r=froydnj,hsivonen.
Browse files Browse the repository at this point in the history
nsHtml5Atoms are very similar to dynamic nsAtoms. This patch removes the former
in favour of the latter, which leaves nsAtom as the only subclass of nsIAtom.

nsAtom::mKind is still used to distinguish dynamic atoms from HTML5 atoms, and
the HTML5 parser still uses manual memory management to handle its HTML5 atoms.

nsHtml5AtomEntry::mAtom had to be changed from an nsAutoPtr to a raw pointer
because nsAtom's destructor is private.

MozReview-Commit-ID: 1pBzwkog3ut

--HG--
extra : rebase_source : fbb819e527cb30606348da9ce3eede62e00fb936
  • Loading branch information
nnethercote committed Sep 21, 2017
1 parent de07428 commit 5018bb4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 116 deletions.
1 change: 0 additions & 1 deletion parser/html/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ EXPORTS += [
]

UNIFIED_SOURCES += [
'nsHtml5Atom.cpp',
'nsHtml5AtomTable.cpp',
'nsHtml5AttributeName.cpp',
'nsHtml5DependentUTF16Buffer.cpp',
Expand Down
63 changes: 0 additions & 63 deletions parser/html/nsHtml5Atom.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions parser/html/nsHtml5Atom.h

This file was deleted.

4 changes: 2 additions & 2 deletions parser/html/nsHtml5AtomTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsHtml5AtomTable.h"
#include "nsHtml5Atom.h"
#include "nsThreadUtils.h"

nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr)
: nsStringHashKey(aStr)
, mAtom(new nsHtml5Atom(*aStr))
, mAtom(new nsAtom(nsAtom::AtomKind::HTML5Atom, *aStr, 0))
{
}

Expand All @@ -21,6 +20,7 @@ nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther)

nsHtml5AtomEntry::~nsHtml5AtomEntry()
{
delete mAtom;
}

nsHtml5AtomTable::nsHtml5AtomTable()
Expand Down
10 changes: 2 additions & 8 deletions parser/html/nsHtml5AtomTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@

#include "nsHashKeys.h"
#include "nsTHashtable.h"
#include "nsAutoPtr.h"
#include "nsIAtom.h"
#include "nsISerialEventTarget.h"

#define RECENTLY_USED_PARSER_ATOMS_SIZE 31

class nsHtml5Atom;

class nsHtml5AtomEntry : public nsStringHashKey
{
public:
explicit nsHtml5AtomEntry(KeyTypePointer aStr);
nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther);
~nsHtml5AtomEntry();
inline nsHtml5Atom* GetAtom()
{
return mAtom;
}
inline nsAtom* GetAtom() { return mAtom; }
private:
nsAutoPtr<nsHtml5Atom> mAtom;
nsAtom* mAtom;
};

/**
Expand Down
1 change: 1 addition & 0 deletions parser/html/nsHtml5SpeculativeLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "nsHtml5SpeculativeLoad.h"
#include "nsHtml5TreeOpExecutor.h"
#include "mozilla/Encoding.h"

nsHtml5SpeculativeLoad::nsHtml5SpeculativeLoad()
:
Expand Down
29 changes: 17 additions & 12 deletions xpcom/ds/nsAtomTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ class FakeBufferRefcountHelper
UniquePtr<nsTArray<FakeBufferRefcountHelper>> gFakeBuffers;
#endif

// This constructor is for dynamic atoms.
nsAtom::nsAtom(const nsAString& aString, uint32_t aHash)
// This constructor is for dynamic atoms and HTML5 atoms.
nsAtom::nsAtom(AtomKind aKind, const nsAString& aString, uint32_t aHash)
: mRefCnt(1)
{
mLength = aString.Length();
SetKind(AtomKind::DynamicAtom);
SetKind(aKind);
MOZ_ASSERT(IsDynamicAtom() || IsHTML5Atom());
RefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
if (buf) {
mString = static_cast<char16_t*>(buf->Data());
Expand All @@ -158,7 +159,7 @@ nsAtom::nsAtom(const nsAString& aString, uint32_t aHash)
}

mHash = aHash;
MOZ_ASSERT(mHash == HashString(mString, mLength));
MOZ_ASSERT_IF(IsDynamicAtom(), mHash == HashString(mString, mLength));

NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated");
NS_ASSERTION(buf && buf->StorageSize() >= (mLength + 1) * sizeof(char16_t),
Expand Down Expand Up @@ -202,10 +203,9 @@ nsAtom::nsAtom(nsStringBuffer* aStringBuffer, uint32_t aLength, uint32_t aHash)
// GCAtomTableLocked() for dynamic atoms), not an nsIAtom* pointer.
nsAtom::~nsAtom()
{
if (IsDynamicAtom()) {
if (!IsStaticAtom()) {
MOZ_ASSERT(IsDynamicAtom() || IsHTML5Atom());
nsStringBuffer::FromData(mString)->Release();
} else {
MOZ_ASSERT(IsStaticAtom());
}
}

Expand All @@ -214,13 +214,15 @@ NS_IMPL_QUERY_INTERFACE(nsAtom, nsIAtom);
NS_IMETHODIMP
nsAtom::ToUTF8String(nsACString& aBuf)
{
MOZ_ASSERT(!IsHTML5Atom(), "Called ToUTF8String() on an HTML5 atom");
CopyUTF16toUTF8(nsDependentString(mString, mLength), aBuf);
return NS_OK;
}

NS_IMETHODIMP_(size_t)
nsAtom::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
{
MOZ_ASSERT(!IsHTML5Atom(), "Called SizeOfIncludingThis() on an HTML5 atom");
size_t n = aMallocSizeOf(this);
// String buffers pointed to by static atoms are in static memory, and so
// are not measured here.
Expand All @@ -238,7 +240,7 @@ nsAtom::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
NS_IMETHODIMP_(MozExternalRefCountType)
nsIAtom::AddRef()
{
MOZ_ASSERT(!IsHTML5Atom(), "Attempt to AddRef an nsHtml5Atom");
MOZ_ASSERT(!IsHTML5Atom(), "Attempt to AddRef an HTML5 atom");
if (!IsDynamicAtom()) {
MOZ_ASSERT(IsStaticAtom());
return 2;
Expand All @@ -249,7 +251,7 @@ nsIAtom::AddRef()
NS_IMETHODIMP_(MozExternalRefCountType)
nsIAtom::Release()
{
MOZ_ASSERT(!IsHTML5Atom(), "Attempt to Release an nsHtml5Atom");
MOZ_ASSERT(!IsHTML5Atom(), "Attempt to Release an HTML5 atom");
if (!IsDynamicAtom()) {
MOZ_ASSERT(IsStaticAtom());
return 1;
Expand Down Expand Up @@ -721,7 +723,8 @@ nsAtomFriend::Atomize(const nsACString& aUTF8String)
// Actually, now there is, sort of: ForgetSharedBuffer.
nsString str;
CopyUTF8toUTF16(aUTF8String, str);
RefPtr<nsAtom> atom = dont_AddRef(new nsAtom(str, hash));
RefPtr<nsAtom> atom =
dont_AddRef(new nsAtom(nsAtom::AtomKind::DynamicAtom, str, hash));

he->mAtom = atom;

Expand Down Expand Up @@ -755,7 +758,8 @@ nsAtomFriend::Atomize(const nsAString& aUTF16String)
return atom.forget();
}

RefPtr<nsAtom> atom = dont_AddRef(new nsAtom(aUTF16String, hash));
RefPtr<nsAtom> atom =
dont_AddRef(new nsAtom(nsAtom::AtomKind::DynamicAtom, aUTF16String, hash));
he->mAtom = atom;

return atom.forget();
Expand Down Expand Up @@ -792,7 +796,8 @@ nsAtomFriend::AtomizeMainThread(const nsAString& aUTF16String)
if (he->mAtom) {
retVal = he->mAtom;
} else {
RefPtr<nsAtom> newAtom = dont_AddRef(new nsAtom(aUTF16String, hash));
RefPtr<nsAtom> newAtom = dont_AddRef(
new nsAtom(nsAtom::AtomKind::DynamicAtom, aUTF16String, hash));
he->mAtom = newAtom;
retVal = newAtom.forget();
}
Expand Down
9 changes: 7 additions & 2 deletions xpcom/ds/nsIAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class nsIAtom : public nsISupports

// A hashcode that is better distributed than the actual atom pointer, for
// use in situations that need a well-distributed hashcode.
uint32_t hash() const { return mHash; }
uint32_t hash() const
{
MOZ_ASSERT(!IsHTML5Atom());
return mHash;
}

protected:
uint32_t mLength: 30;
Expand Down Expand Up @@ -107,9 +111,10 @@ class nsAtom final : public nsIAtom
private:
friend class nsIAtom;
friend class nsAtomFriend;
friend class nsHtml5AtomEntry;

// Construction and destruction is done entirely by |friend|s.
nsAtom(const nsAString& aString, uint32_t aHash);
nsAtom(AtomKind aKind, const nsAString& aString, uint32_t aHash);
nsAtom(nsStringBuffer* aStringBuffer, uint32_t aLength, uint32_t aHash);
~nsAtom();

Expand Down

0 comments on commit 5018bb4

Please sign in to comment.