Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / parser / html / nsHtml5OwningUTF16Buffer.cpp
blobdcd2aec196a71c0e65951d5ca64a7a401586ff3a
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsHtml5OwningUTF16Buffer.h"
7 nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(char16_t* aBuffer)
8 : nsHtml5UTF16Buffer(aBuffer, 0),
9 next(nullptr),
10 key(nullptr)
12 MOZ_COUNT_CTOR(nsHtml5OwningUTF16Buffer);
15 nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(void* aKey)
16 : nsHtml5UTF16Buffer(nullptr, 0),
17 next(nullptr),
18 key(aKey)
20 MOZ_COUNT_CTOR(nsHtml5OwningUTF16Buffer);
23 nsHtml5OwningUTF16Buffer::~nsHtml5OwningUTF16Buffer()
25 MOZ_COUNT_DTOR(nsHtml5OwningUTF16Buffer);
26 DeleteBuffer();
28 // This is to avoid dtor recursion on 'next', bug 706932.
29 nsRefPtr<nsHtml5OwningUTF16Buffer> tail;
30 tail.swap(next);
31 while (tail && tail->mRefCnt == 1) {
32 nsRefPtr<nsHtml5OwningUTF16Buffer> tmp;
33 tmp.swap(tail->next);
34 tail.swap(tmp);
38 // static
39 already_AddRefed<nsHtml5OwningUTF16Buffer>
40 nsHtml5OwningUTF16Buffer::FalliblyCreate(int32_t aLength)
42 const mozilla::fallible_t fallible = mozilla::fallible_t();
43 char16_t* newBuf = new (fallible) char16_t[aLength];
44 if (!newBuf) {
45 return nullptr;
47 nsRefPtr<nsHtml5OwningUTF16Buffer> newObj =
48 new (fallible) nsHtml5OwningUTF16Buffer(newBuf);
49 if (!newObj) {
50 delete[] newBuf;
51 return nullptr;
53 return newObj.forget();
56 void
57 nsHtml5OwningUTF16Buffer::Swap(nsHtml5OwningUTF16Buffer* aOther)
59 nsHtml5UTF16Buffer::Swap(aOther);
63 // Not using macros for AddRef and Release in order to be able to refcount on
64 // and create on different threads.
66 nsrefcnt
67 nsHtml5OwningUTF16Buffer::AddRef()
69 NS_PRECONDITION(int32_t(mRefCnt) >= 0, "Illegal refcount.");
70 ++mRefCnt;
71 NS_LOG_ADDREF(this, mRefCnt, "nsHtml5OwningUTF16Buffer", sizeof(*this));
72 return mRefCnt;
75 nsrefcnt
76 nsHtml5OwningUTF16Buffer::Release()
78 NS_PRECONDITION(0 != mRefCnt, "Release without AddRef.");
79 --mRefCnt;
80 NS_LOG_RELEASE(this, mRefCnt, "nsHtml5OwningUTF16Buffer");
81 if (mRefCnt == 0) {
82 mRefCnt = 1; /* stabilize */
83 delete this;
84 return 0;
86 return mRefCnt;