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),
12 MOZ_COUNT_CTOR(nsHtml5OwningUTF16Buffer
);
15 nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(void* aKey
)
16 : nsHtml5UTF16Buffer(nullptr, 0),
20 MOZ_COUNT_CTOR(nsHtml5OwningUTF16Buffer
);
23 nsHtml5OwningUTF16Buffer::~nsHtml5OwningUTF16Buffer()
25 MOZ_COUNT_DTOR(nsHtml5OwningUTF16Buffer
);
28 // This is to avoid dtor recursion on 'next', bug 706932.
29 nsRefPtr
<nsHtml5OwningUTF16Buffer
> tail
;
31 while (tail
&& tail
->mRefCnt
== 1) {
32 nsRefPtr
<nsHtml5OwningUTF16Buffer
> tmp
;
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
];
47 nsRefPtr
<nsHtml5OwningUTF16Buffer
> newObj
=
48 new (fallible
) nsHtml5OwningUTF16Buffer(newBuf
);
53 return newObj
.forget();
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.
67 nsHtml5OwningUTF16Buffer::AddRef()
69 NS_PRECONDITION(int32_t(mRefCnt
) >= 0, "Illegal refcount.");
71 NS_LOG_ADDREF(this, mRefCnt
, "nsHtml5OwningUTF16Buffer", sizeof(*this));
76 nsHtml5OwningUTF16Buffer::Release()
78 NS_PRECONDITION(0 != mRefCnt
, "Release without AddRef.");
80 NS_LOG_RELEASE(this, mRefCnt
, "nsHtml5OwningUTF16Buffer");
82 mRefCnt
= 1; /* stabilize */