2012-05-29 19:52:43 +04:00
|
|
|
/* 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/. */
|
2009-09-18 19:13:10 +04:00
|
|
|
|
|
|
|
#include "nsHtml5Atom.h"
|
2013-04-22 15:13:22 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2009-09-18 19:13:10 +04:00
|
|
|
|
|
|
|
nsHtml5Atom::nsHtml5Atom(const nsAString& aString)
|
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
mLength = aString.Length();
|
2016-04-06 04:28:40 +03:00
|
|
|
mIsStatic = false;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStringBuffer> buf = nsStringBuffer::FromString(aString);
|
2010-03-08 18:45:00 +03:00
|
|
|
if (buf) {
|
2014-01-04 19:02:17 +04:00
|
|
|
mString = static_cast<char16_t*>(buf->Data());
|
2013-04-22 15:13:22 +04:00
|
|
|
} else {
|
2016-04-07 02:35:50 +03:00
|
|
|
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);
|
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
mString = static_cast<char16_t*>(buf->Data());
|
2010-03-08 18:45:00 +03:00
|
|
|
CopyUnicodeTo(aString, 0, mString, mLength);
|
2014-01-04 19:02:17 +04:00
|
|
|
mString[mLength] = char16_t(0);
|
2010-03-08 18:45:00 +03:00
|
|
|
}
|
2010-03-08 19:03:55 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(mString[mLength] == char16_t(0), "null terminated");
|
|
|
|
NS_ASSERTION(buf && buf->StorageSize() >= (mLength+1) * sizeof(char16_t),
|
2010-03-08 19:03:55 +03:00
|
|
|
"enough storage");
|
|
|
|
NS_ASSERTION(Equals(aString), "correct data");
|
2013-04-22 15:13:22 +04:00
|
|
|
|
|
|
|
// Take ownership of buffer
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << buf.forget();
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5Atom::~nsHtml5Atom()
|
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
nsStringBuffer::FromData(mString)->Release();
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2009-09-18 19:13:10 +04:00
|
|
|
nsHtml5Atom::AddRef()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to AddRef an nsHtml5Atom.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2009-09-18 19:13:10 +04:00
|
|
|
nsHtml5Atom::Release()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to Release an nsHtml5Atom.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Attempt to call QueryInterface an nsHtml5Atom.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHtml5Atom::ScriptableToString(nsAString& aBuf)
|
2009-09-18 19:13:10 +04:00
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_NOTREACHED("Should not call ScriptableToString.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsHtml5Atom::ScriptableEquals(const nsAString& aString, bool* aResult)
|
2009-09-18 19:13:10 +04:00
|
|
|
{
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_NOTREACHED("Should not call ScriptableEquals.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2009-09-18 19:13:10 +04:00
|
|
|
}
|
Bug 1261735 (part 1) - Overhaul the atom implementation. r=froydnj,erahm.
This patch changes things so that dynamic atoms and static atoms have distinct
implementations. This is a step towards allowing dynamic atoms and static atoms
to have different layouts in memory, which will allow static atoms to be
represented more compactly.
Specifically, the patch does the following.
- It renames AtomImpl as DynamicAtom and PermanentAtomImpl as StaticAtom, and
the latter is no longer a subclass of the former. This required duplicating
some methods from the former into the latter: ScriptableToString(),
ToUTF8String(), ScriptableEquals(), IsStaticAtom(). (This duplication will
disappear in the future if the representations of dynamic atoms and static
atoms diverge. Indeed, SizeOfIncludingThis() is already different in the two
classes.)
- It replaces all mentions of "permanent"/"non-permanent" atoms with
"static"/"dynamic".
- In ~DynamicAtom() it removes the check that causes gAtomTable to be deleted
when it becomes empty. This will only happen at shutdown and so doesn't seem
useful.
- It documents better various things, especially the basics of the
dynamic/static split, the transmutation of dynamic atoms to static atoms, and
the details of the SizeOf functions.
--HG--
extra : rebase_source : dbf903012e70ebf1a43de1e1088db1bc1b8dd4f4
2016-04-01 03:18:06 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP_(size_t)
|
|
|
|
nsHtml5Atom::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Should not call SizeOfIncludingThis.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|