Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/parser/html/nsHtml5OwningUTF16Buffer.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
4
5
#include "nsHtml5OwningUTF16Buffer.h"
6
7
#include "mozilla/Span.h"
8
9
using namespace mozilla;
10
11
nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(char16_t* aBuffer)
12
  : nsHtml5UTF16Buffer(aBuffer, 0)
13
  , next(nullptr)
14
  , key(nullptr)
15
0
{
16
0
}
17
18
nsHtml5OwningUTF16Buffer::nsHtml5OwningUTF16Buffer(void* aKey)
19
  : nsHtml5UTF16Buffer(nullptr, 0)
20
  , next(nullptr)
21
  , key(aKey)
22
0
{
23
0
}
24
25
nsHtml5OwningUTF16Buffer::~nsHtml5OwningUTF16Buffer()
26
0
{
27
0
  DeleteBuffer();
28
0
29
0
  // This is to avoid dtor recursion on 'next', bug 706932.
30
0
  RefPtr<nsHtml5OwningUTF16Buffer> tail;
31
0
  tail.swap(next);
32
0
  while (tail && tail->mRefCnt == 1) {
33
0
    RefPtr<nsHtml5OwningUTF16Buffer> tmp;
34
0
    tmp.swap(tail->next);
35
0
    tail.swap(tmp);
36
0
  }
37
0
}
38
39
// static
40
already_AddRefed<nsHtml5OwningUTF16Buffer>
41
nsHtml5OwningUTF16Buffer::FalliblyCreate(int32_t aLength)
42
0
{
43
0
  char16_t* newBuf = new (mozilla::fallible) char16_t[aLength];
44
0
  if (!newBuf) {
45
0
    return nullptr;
46
0
  }
47
0
  RefPtr<nsHtml5OwningUTF16Buffer> newObj =
48
0
    new (mozilla::fallible) nsHtml5OwningUTF16Buffer(newBuf);
49
0
  if (!newObj) {
50
0
    delete[] newBuf;
51
0
    return nullptr;
52
0
  }
53
0
  return newObj.forget();
54
0
}
55
56
void
57
nsHtml5OwningUTF16Buffer::Swap(nsHtml5OwningUTF16Buffer* aOther)
58
0
{
59
0
  nsHtml5UTF16Buffer::Swap(aOther);
60
0
}
61
62
Span<char16_t>
63
nsHtml5OwningUTF16Buffer::TailAsSpan(int32_t aBufferSize)
64
0
{
65
0
  MOZ_ASSERT(aBufferSize >= getEnd());
66
0
  return MakeSpan(getBuffer() + getEnd(), aBufferSize - getEnd());
67
0
}
68
69
void
70
nsHtml5OwningUTF16Buffer::AdvanceEnd(int32_t aNumberOfCodeUnits)
71
0
{
72
0
  setEnd(getEnd() + aNumberOfCodeUnits);
73
0
}
74
75
// Not using macros for AddRef and Release in order to be able to refcount on
76
// and create on different threads.
77
78
nsrefcnt
79
nsHtml5OwningUTF16Buffer::AddRef()
80
0
{
81
0
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "Illegal refcount.");
82
0
  ++mRefCnt;
83
0
  NS_LOG_ADDREF(this, mRefCnt, "nsHtml5OwningUTF16Buffer", sizeof(*this));
84
0
  return mRefCnt;
85
0
}
86
87
nsrefcnt
88
nsHtml5OwningUTF16Buffer::Release()
89
0
{
90
0
  MOZ_ASSERT(0 != mRefCnt, "Release without AddRef.");
91
0
  --mRefCnt;
92
0
  NS_LOG_RELEASE(this, mRefCnt, "nsHtml5OwningUTF16Buffer");
93
0
  if (mRefCnt == 0) {
94
0
    mRefCnt = 1; /* stabilize */
95
0
    delete this;
96
0
    return 0;
97
0
  }
98
0
  return mRefCnt;
99
0
}