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 #include "mozilla/Span.h"
9 using namespace mozilla
;
11 nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(char16_t
* aBuffer
)
12 : nsHtml5UTF16Buffer(aBuffer
, 0), next(nullptr), key(nullptr) {}
14 nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(void* aKey
)
15 : nsHtml5UTF16Buffer(nullptr, 0), next(nullptr), key(aKey
) {}
17 nsHtml5OwningUTF16Buffer::~nsHtml5OwningUTF16Buffer() {
20 // This is to avoid dtor recursion on 'next', bug 706932.
21 RefPtr
<nsHtml5OwningUTF16Buffer
> tail
;
23 while (tail
&& tail
->mRefCnt
== 1) {
24 RefPtr
<nsHtml5OwningUTF16Buffer
> tmp
;
31 already_AddRefed
<nsHtml5OwningUTF16Buffer
>
32 nsHtml5OwningUTF16Buffer::FalliblyCreate(int32_t aLength
) {
33 char16_t
* newBuf
= new (mozilla::fallible
) char16_t
[aLength
];
37 RefPtr
<nsHtml5OwningUTF16Buffer
> newObj
=
38 new (mozilla::fallible
) nsHtml5OwningUTF16Buffer(newBuf
);
43 return newObj
.forget();
46 void nsHtml5OwningUTF16Buffer::Swap(nsHtml5OwningUTF16Buffer
* aOther
) {
47 nsHtml5UTF16Buffer::Swap(aOther
);
50 Span
<char16_t
> nsHtml5OwningUTF16Buffer::TailAsSpan(int32_t aBufferSize
) {
51 MOZ_ASSERT(aBufferSize
>= getEnd());
52 return {getBuffer() + getEnd(), static_cast<size_t>(aBufferSize
- getEnd())};
55 void nsHtml5OwningUTF16Buffer::AdvanceEnd(int32_t aNumberOfCodeUnits
) {
56 setEnd(getEnd() + aNumberOfCodeUnits
);