зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1401873 - Remove nsHtml5Atom. r=froydnj,hsivonen.
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
This commit is contained in:
Родитель
de07428d79
Коммит
5018bb4f9b
|
@ -55,7 +55,6 @@ EXPORTS += [
|
|||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsHtml5Atom.cpp',
|
||||
'nsHtml5AtomTable.cpp',
|
||||
'nsHtml5AttributeName.cpp',
|
||||
'nsHtml5DependentUTF16Buffer.cpp',
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsHtml5Atom.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
|
||||
{
|
||||
mLength = aString.Length();
|
||||
SetKind(AtomKind::HTML5Atom);
|
||||
RefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
|
||||
if (buf) {
|
||||
mString = static_cast<char16_t*>(buf->Data());
|
||||
} else {
|
||||
const size_t size = (mLength + 1) * sizeof(char16_t);
|
||||
buf = nsStringBuffer::Alloc(size);
|
||||
if (MOZ_UNLIKELY(!buf)) {
|
||||
// We OOM because atom allocations should be small and it's hard to
|
||||
// handle them more gracefully in a constructor.
|
||||
NS_ABORT_OOM(size);
|
||||
}
|
||||
mString = static_cast<char16_t*>(buf->Data());
|
||||
CopyUnicodeTo(aString, 0, mString, mLength);
|
||||
mString[mLength] = char16_t(0);
|
||||
}
|
||||
|
||||
NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated");
|
||||
NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(char16_t),
|
||||
"enough storage");
|
||||
NS_ASSERTION(Equals(aString), "correct data");
|
||||
|
||||
// Take ownership of buffer
|
||||
mozilla::Unused << buf.forget();
|
||||
}
|
||||
|
||||
nsHtml5Atom::~nsHtml5Atom()
|
||||
{
|
||||
nsStringBuffer::FromData(mString)->Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom.");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHtml5Atom::ToUTF8String(nsACString& aReturn)
|
||||
{
|
||||
NS_NOTREACHED("Should not attempt to convert to an UTF-8 string.");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(size_t)
|
||||
nsHtml5Atom::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
||||
{
|
||||
NS_NOTREACHED("Should not call SizeOfIncludingThis.");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsHtml5Atom_h
|
||||
#define nsHtml5Atom_h
|
||||
|
||||
#include "nsIAtom.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
/**
|
||||
* A dynamic atom implementation meant for use within the nsHtml5Tokenizer and
|
||||
* nsHtml5TreeBuilder owned by one nsHtml5Parser or nsHtml5StreamParser
|
||||
* instance.
|
||||
*
|
||||
* Usage is documented in nsHtml5AtomTable and nsIAtom.
|
||||
*/
|
||||
class nsHtml5Atom final : public nsIAtom
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) final;
|
||||
NS_DECL_NSIATOM
|
||||
|
||||
explicit nsHtml5Atom(const nsAString& aString);
|
||||
~nsHtml5Atom();
|
||||
};
|
||||
|
||||
#endif // nsHtml5Atom_h
|
|
@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -21,6 +20,7 @@ nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther)
|
|||
|
||||
nsHtml5AtomEntry::~nsHtml5AtomEntry()
|
||||
{
|
||||
delete mAtom;
|
||||
}
|
||||
|
||||
nsHtml5AtomTable::nsHtml5AtomTable()
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "nsHtml5SpeculativeLoad.h"
|
||||
#include "nsHtml5TreeOpExecutor.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
|
||||
nsHtml5SpeculativeLoad::nsHtml5SpeculativeLoad()
|
||||
:
|
||||
|
|
|
@ -135,12 +135,13 @@ private:
|
|||
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());
|
||||
|
@ -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),
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,6 +214,7 @@ 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;
|
||||
}
|
||||
|
@ -221,6 +222,7 @@ nsAtom::ToUTF8String(nsACString& aBuf)
|
|||
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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,11 @@ public:
|
|||
|
||||
// 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;
|
||||
|
@ -107,9 +111,10 @@ public:
|
|||
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();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче