Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsTArray-inl.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef nsTArray_h__
8
#  error "Don't include this file directly"
9
#endif
10
11
template<class Alloc, class Copy>
12
nsTArray_base<Alloc, Copy>::nsTArray_base()
13
  : mHdr(EmptyHdr())
14
13.2M
{
15
13.2M
  MOZ_COUNT_CTOR(nsTArray_base);
16
13.2M
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::nsTArray_base()
Line
Count
Source
14
13.2M
{
15
13.2M
  MOZ_COUNT_CTOR(nsTArray_base);
16
13.2M
}
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::nsTArray_base()
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::intl::Locale> >::nsTArray_base()
Line
Count
Source
14
3
{
15
3
  MOZ_COUNT_CTOR(nsTArray_base);
16
3
}
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ipc::StructuredCloneData> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> > >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::media::TimeIntervals> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<std::__1::function<mozilla::SupportChecker::CheckResult ()> > >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioSegment> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::StructuredCloneReadInfo> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::PaintedLayerData> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::nsTArray_base()
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::nsTArray_base()
17
18
template<class Alloc, class Copy>
19
nsTArray_base<Alloc, Copy>::~nsTArray_base()
20
13.2M
{
21
13.2M
  if (mHdr != EmptyHdr() && !UsesAutoArrayBuffer()) {
22
669k
    Alloc::Free(mHdr);
23
669k
  }
24
13.2M
  MOZ_COUNT_DTOR(nsTArray_base);
25
13.2M
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::~nsTArray_base()
Line
Count
Source
20
13.2M
{
21
13.2M
  if (mHdr != EmptyHdr() && !UsesAutoArrayBuffer()) {
22
669k
    Alloc::Free(mHdr);
23
669k
  }
24
13.2M
  MOZ_COUNT_DTOR(nsTArray_base);
25
13.2M
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::intl::Locale> >::~nsTArray_base()
Line
Count
Source
20
3
{
21
3
  if (mHdr != EmptyHdr() && !UsesAutoArrayBuffer()) {
22
0
    Alloc::Free(mHdr);
23
0
  }
24
3
  MOZ_COUNT_DTOR(nsTArray_base);
25
3
}
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ipc::StructuredCloneData> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> > >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::media::TimeIntervals> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<std::__1::function<mozilla::SupportChecker::CheckResult ()> > >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioSegment> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::StructuredCloneReadInfo> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::PaintedLayerData> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::~nsTArray_base()
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::~nsTArray_base()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::~nsTArray_base()
26
27
template<class Alloc, class Copy>
28
const nsTArrayHeader*
29
nsTArray_base<Alloc, Copy>::GetAutoArrayBufferUnsafe(size_t aElemAlign) const
30
6.49M
{
31
6.49M
  // Assuming |this| points to an nsAutoArray, we want to get a pointer to
32
6.49M
  // mAutoBuf.  So just cast |this| to nsAutoArray* and read &mAutoBuf!
33
6.49M
34
6.49M
  const void* autoBuf =
35
6.49M
    &reinterpret_cast<const AutoTArray<nsTArray<uint32_t>, 1>*>(this)->mAutoBuf;
36
6.49M
37
6.49M
  // If we're on a 32-bit system and aElemAlign is 8, we need to adjust our
38
6.49M
  // pointer to take into account the extra alignment in the auto array.
39
6.49M
40
6.49M
  static_assert(sizeof(void*) != 4 ||
41
6.49M
                (MOZ_ALIGNOF(mozilla::AlignedElem<8>) == 8 &&
42
6.49M
                 sizeof(AutoTArray<mozilla::AlignedElem<8>, 1>) ==
43
6.49M
                   sizeof(void*) + sizeof(nsTArrayHeader) +
44
6.49M
                   4 + sizeof(mozilla::AlignedElem<8>)),
45
6.49M
                "auto array padding wasn't what we expected");
46
6.49M
47
6.49M
  // We don't support alignments greater than 8 bytes.
48
6.49M
  MOZ_ASSERT(aElemAlign <= 4 || aElemAlign == 8,
49
6.49M
             "unsupported alignment.");
50
6.49M
  if (sizeof(void*) == 4 && aElemAlign == 8) {
51
0
    autoBuf = reinterpret_cast<const char*>(autoBuf) + 4;
52
0
  }
53
6.49M
54
6.49M
  return reinterpret_cast<const Header*>(autoBuf);
55
6.49M
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::GetAutoArrayBufferUnsafe(unsigned long) const
Line
Count
Source
30
6.49M
{
31
6.49M
  // Assuming |this| points to an nsAutoArray, we want to get a pointer to
32
6.49M
  // mAutoBuf.  So just cast |this| to nsAutoArray* and read &mAutoBuf!
33
6.49M
34
6.49M
  const void* autoBuf =
35
6.49M
    &reinterpret_cast<const AutoTArray<nsTArray<uint32_t>, 1>*>(this)->mAutoBuf;
36
6.49M
37
6.49M
  // If we're on a 32-bit system and aElemAlign is 8, we need to adjust our
38
6.49M
  // pointer to take into account the extra alignment in the auto array.
39
6.49M
40
6.49M
  static_assert(sizeof(void*) != 4 ||
41
6.49M
                (MOZ_ALIGNOF(mozilla::AlignedElem<8>) == 8 &&
42
6.49M
                 sizeof(AutoTArray<mozilla::AlignedElem<8>, 1>) ==
43
6.49M
                   sizeof(void*) + sizeof(nsTArrayHeader) +
44
6.49M
                   4 + sizeof(mozilla::AlignedElem<8>)),
45
6.49M
                "auto array padding wasn't what we expected");
46
6.49M
47
6.49M
  // We don't support alignments greater than 8 bytes.
48
6.49M
  MOZ_ASSERT(aElemAlign <= 4 || aElemAlign == 8,
49
6.49M
             "unsupported alignment.");
50
6.49M
  if (sizeof(void*) == 4 && aElemAlign == 8) {
51
0
    autoBuf = reinterpret_cast<const char*>(autoBuf) + 4;
52
0
  }
53
6.49M
54
6.49M
  return reinterpret_cast<const Header*>(autoBuf);
55
6.49M
}
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::GetAutoArrayBufferUnsafe(unsigned long) const
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::intl::Locale> >::GetAutoArrayBufferUnsafe(unsigned long) const
Line
Count
Source
30
3
{
31
3
  // Assuming |this| points to an nsAutoArray, we want to get a pointer to
32
3
  // mAutoBuf.  So just cast |this| to nsAutoArray* and read &mAutoBuf!
33
3
34
3
  const void* autoBuf =
35
3
    &reinterpret_cast<const AutoTArray<nsTArray<uint32_t>, 1>*>(this)->mAutoBuf;
36
3
37
3
  // If we're on a 32-bit system and aElemAlign is 8, we need to adjust our
38
3
  // pointer to take into account the extra alignment in the auto array.
39
3
40
3
  static_assert(sizeof(void*) != 4 ||
41
3
                (MOZ_ALIGNOF(mozilla::AlignedElem<8>) == 8 &&
42
3
                 sizeof(AutoTArray<mozilla::AlignedElem<8>, 1>) ==
43
3
                   sizeof(void*) + sizeof(nsTArrayHeader) +
44
3
                   4 + sizeof(mozilla::AlignedElem<8>)),
45
3
                "auto array padding wasn't what we expected");
46
3
47
3
  // We don't support alignments greater than 8 bytes.
48
3
  MOZ_ASSERT(aElemAlign <= 4 || aElemAlign == 8,
49
3
             "unsupported alignment.");
50
3
  if (sizeof(void*) == 4 && aElemAlign == 8) {
51
0
    autoBuf = reinterpret_cast<const char*>(autoBuf) + 4;
52
0
  }
53
3
54
3
  return reinterpret_cast<const Header*>(autoBuf);
55
3
}
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ipc::StructuredCloneData> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> > >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::media::TimeIntervals> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<std::__1::function<mozilla::SupportChecker::CheckResult ()> > >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioSegment> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::StructuredCloneReadInfo> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::PaintedLayerData> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::GetAutoArrayBufferUnsafe(unsigned long) const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::GetAutoArrayBufferUnsafe(unsigned long) const
56
57
template<class Alloc, class Copy>
58
bool
59
nsTArray_base<Alloc, Copy>::UsesAutoArrayBuffer() const
60
7.51M
{
61
7.51M
  if (!mHdr->mIsAutoArray) {
62
1.01M
    return false;
63
1.01M
  }
64
6.49M
65
6.49M
  // This is nuts.  If we were sane, we'd pass aElemAlign as a parameter to
66
6.49M
  // this function.  Unfortunately this function is called in nsTArray_base's
67
6.49M
  // destructor, at which point we don't know elem_type's alignment.
68
6.49M
  //
69
6.49M
  // We'll fall on our face and return true when we should say false if
70
6.49M
  //
71
6.49M
  //   * we're not using our auto buffer,
72
6.49M
  //   * aElemAlign == 4, and
73
6.49M
  //   * mHdr == GetAutoArrayBuffer(8).
74
6.49M
  //
75
6.49M
  // This could happen if |*this| lives on the heap and malloc allocated our
76
6.49M
  // buffer on the heap adjacent to |*this|.
77
6.49M
  //
78
6.49M
  // However, we can show that this can't happen.  If |this| is an auto array
79
6.49M
  // (as we ensured at the beginning of the method), GetAutoArrayBuffer(8)
80
6.49M
  // always points to memory owned by |*this|, because (as we assert below)
81
6.49M
  //
82
6.49M
  //   * GetAutoArrayBuffer(8) is at most 4 bytes past GetAutoArrayBuffer(4), and
83
6.49M
  //   * sizeof(nsTArrayHeader) > 4.
84
6.49M
  //
85
6.49M
  // Since AutoTArray always contains an nsTArrayHeader,
86
6.49M
  // GetAutoArrayBuffer(8) will always point inside the auto array object,
87
6.49M
  // even if it doesn't point at the beginning of the header.
88
6.49M
  //
89
6.49M
  // Note that this means that we can't store elements with alignment 16 in an
90
6.49M
  // nsTArray, because GetAutoArrayBuffer(16) could lie outside the memory
91
6.49M
  // owned by this AutoTArray.  We statically assert that elem_type's
92
6.49M
  // alignment is 8 bytes or less in AutoTArray.
93
6.49M
94
6.49M
  static_assert(sizeof(nsTArrayHeader) > 4,
95
6.49M
                "see comment above");
96
6.49M
97
#ifdef DEBUG
98
  ptrdiff_t diff = reinterpret_cast<const char*>(GetAutoArrayBuffer(8)) -
99
                   reinterpret_cast<const char*>(GetAutoArrayBuffer(4));
100
  MOZ_ASSERT(diff >= 0 && diff <= 4,
101
             "GetAutoArrayBuffer doesn't do what we expect.");
102
#endif
103
104
6.49M
  return mHdr == GetAutoArrayBuffer(4) || mHdr == GetAutoArrayBuffer(8);
105
6.49M
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::UsesAutoArrayBuffer() const
Line
Count
Source
60
7.51M
{
61
7.51M
  if (!mHdr->mIsAutoArray) {
62
1.01M
    return false;
63
1.01M
  }
64
6.49M
65
6.49M
  // This is nuts.  If we were sane, we'd pass aElemAlign as a parameter to
66
6.49M
  // this function.  Unfortunately this function is called in nsTArray_base's
67
6.49M
  // destructor, at which point we don't know elem_type's alignment.
68
6.49M
  //
69
6.49M
  // We'll fall on our face and return true when we should say false if
70
6.49M
  //
71
6.49M
  //   * we're not using our auto buffer,
72
6.49M
  //   * aElemAlign == 4, and
73
6.49M
  //   * mHdr == GetAutoArrayBuffer(8).
74
6.49M
  //
75
6.49M
  // This could happen if |*this| lives on the heap and malloc allocated our
76
6.49M
  // buffer on the heap adjacent to |*this|.
77
6.49M
  //
78
6.49M
  // However, we can show that this can't happen.  If |this| is an auto array
79
6.49M
  // (as we ensured at the beginning of the method), GetAutoArrayBuffer(8)
80
6.49M
  // always points to memory owned by |*this|, because (as we assert below)
81
6.49M
  //
82
6.49M
  //   * GetAutoArrayBuffer(8) is at most 4 bytes past GetAutoArrayBuffer(4), and
83
6.49M
  //   * sizeof(nsTArrayHeader) > 4.
84
6.49M
  //
85
6.49M
  // Since AutoTArray always contains an nsTArrayHeader,
86
6.49M
  // GetAutoArrayBuffer(8) will always point inside the auto array object,
87
6.49M
  // even if it doesn't point at the beginning of the header.
88
6.49M
  //
89
6.49M
  // Note that this means that we can't store elements with alignment 16 in an
90
6.49M
  // nsTArray, because GetAutoArrayBuffer(16) could lie outside the memory
91
6.49M
  // owned by this AutoTArray.  We statically assert that elem_type's
92
6.49M
  // alignment is 8 bytes or less in AutoTArray.
93
6.49M
94
6.49M
  static_assert(sizeof(nsTArrayHeader) > 4,
95
6.49M
                "see comment above");
96
6.49M
97
#ifdef DEBUG
98
  ptrdiff_t diff = reinterpret_cast<const char*>(GetAutoArrayBuffer(8)) -
99
                   reinterpret_cast<const char*>(GetAutoArrayBuffer(4));
100
  MOZ_ASSERT(diff >= 0 && diff <= 4,
101
             "GetAutoArrayBuffer doesn't do what we expect.");
102
#endif
103
104
6.49M
  return mHdr == GetAutoArrayBuffer(4) || mHdr == GetAutoArrayBuffer(8);
105
6.49M
}
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::UsesAutoArrayBuffer() const
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::intl::Locale> >::UsesAutoArrayBuffer() const
Line
Count
Source
60
3
{
61
3
  if (!mHdr->mIsAutoArray) {
62
0
    return false;
63
0
  }
64
3
65
3
  // This is nuts.  If we were sane, we'd pass aElemAlign as a parameter to
66
3
  // this function.  Unfortunately this function is called in nsTArray_base's
67
3
  // destructor, at which point we don't know elem_type's alignment.
68
3
  //
69
3
  // We'll fall on our face and return true when we should say false if
70
3
  //
71
3
  //   * we're not using our auto buffer,
72
3
  //   * aElemAlign == 4, and
73
3
  //   * mHdr == GetAutoArrayBuffer(8).
74
3
  //
75
3
  // This could happen if |*this| lives on the heap and malloc allocated our
76
3
  // buffer on the heap adjacent to |*this|.
77
3
  //
78
3
  // However, we can show that this can't happen.  If |this| is an auto array
79
3
  // (as we ensured at the beginning of the method), GetAutoArrayBuffer(8)
80
3
  // always points to memory owned by |*this|, because (as we assert below)
81
3
  //
82
3
  //   * GetAutoArrayBuffer(8) is at most 4 bytes past GetAutoArrayBuffer(4), and
83
3
  //   * sizeof(nsTArrayHeader) > 4.
84
3
  //
85
3
  // Since AutoTArray always contains an nsTArrayHeader,
86
3
  // GetAutoArrayBuffer(8) will always point inside the auto array object,
87
3
  // even if it doesn't point at the beginning of the header.
88
3
  //
89
3
  // Note that this means that we can't store elements with alignment 16 in an
90
3
  // nsTArray, because GetAutoArrayBuffer(16) could lie outside the memory
91
3
  // owned by this AutoTArray.  We statically assert that elem_type's
92
3
  // alignment is 8 bytes or less in AutoTArray.
93
3
94
3
  static_assert(sizeof(nsTArrayHeader) > 4,
95
3
                "see comment above");
96
3
97
#ifdef DEBUG
98
  ptrdiff_t diff = reinterpret_cast<const char*>(GetAutoArrayBuffer(8)) -
99
                   reinterpret_cast<const char*>(GetAutoArrayBuffer(4));
100
  MOZ_ASSERT(diff >= 0 && diff <= 4,
101
             "GetAutoArrayBuffer doesn't do what we expect.");
102
#endif
103
104
3
  return mHdr == GetAutoArrayBuffer(4) || mHdr == GetAutoArrayBuffer(8);
105
3
}
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ipc::StructuredCloneData> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> > >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::media::TimeIntervals> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<std::__1::function<mozilla::SupportChecker::CheckResult ()> > >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioSegment> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::StructuredCloneReadInfo> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::PaintedLayerData> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::UsesAutoArrayBuffer() const
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::UsesAutoArrayBuffer() const
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::UsesAutoArrayBuffer() const
106
107
// defined in nsTArray.cpp
108
bool IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity,
109
                                                  size_t aElemSize);
110
111
template<class Alloc, class Copy>
112
template<typename ActualAlloc>
113
typename ActualAlloc::ResultTypeProxy
114
nsTArray_base<Alloc, Copy>::EnsureCapacity(size_type aCapacity,
115
                                           size_type aElemSize)
116
14.5M
{
117
14.5M
  // This should be the most common case so test this first
118
14.5M
  if (aCapacity <= mHdr->mCapacity) {
119
13.4M
    return ActualAlloc::SuccessResult();
120
13.4M
  }
121
1.01M
122
1.01M
  // If the requested memory allocation exceeds size_type(-1)/2, then
123
1.01M
  // our doubling algorithm may not be able to allocate it.
124
1.01M
  // Additionally, if it exceeds uint32_t(-1) then we couldn't fit in the
125
1.01M
  // Header::mCapacity member. Just bail out in cases like that.  We don't want
126
1.01M
  // to be allocating 2 GB+ arrays anyway.
127
1.01M
  if (!IsTwiceTheRequiredBytesRepresentableAsUint32(aCapacity, aElemSize)) {
128
0
    ActualAlloc::SizeTooBig((size_t)aCapacity * aElemSize);
129
0
    return ActualAlloc::FailureResult();
130
0
  }
131
1.01M
132
1.01M
  size_t reqSize = sizeof(Header) + aCapacity * aElemSize;
133
1.01M
134
1.01M
  if (mHdr == EmptyHdr()) {
135
985k
    // Malloc() new data
136
985k
    Header* header = static_cast<Header*>(ActualAlloc::Malloc(reqSize));
137
985k
    if (!header) {
138
0
      return ActualAlloc::FailureResult();
139
0
    }
140
985k
    header->mLength = 0;
141
985k
    header->mCapacity = aCapacity;
142
985k
    header->mIsAutoArray = 0;
143
985k
    mHdr = header;
144
985k
145
985k
    return ActualAlloc::SuccessResult();
146
985k
  }
147
33.4k
148
33.4k
  // We increase our capacity so that the allocated buffer grows exponentially,
149
33.4k
  // which gives us amortized O(1) appending. Below the threshold, we use
150
33.4k
  // powers-of-two. Above the threshold, we grow by at least 1.125, rounding up
151
33.4k
  // to the nearest MiB.
152
33.4k
  const size_t slowGrowthThreshold = 8 * 1024 * 1024;
153
33.4k
154
33.4k
  size_t bytesToAlloc;
155
33.4k
  if (reqSize >= slowGrowthThreshold) {
156
0
    size_t currSize = sizeof(Header) + Capacity() * aElemSize;
157
0
    size_t minNewSize = currSize + (currSize >> 3); // multiply by 1.125
158
0
    bytesToAlloc = reqSize > minNewSize ? reqSize : minNewSize;
159
0
160
0
    // Round up to the next multiple of MiB.
161
0
    const size_t MiB = 1 << 20;
162
0
    bytesToAlloc = MiB * ((bytesToAlloc + MiB - 1) / MiB);
163
33.4k
  } else {
164
33.4k
    // Round up to the next power of two.
165
33.4k
    bytesToAlloc = mozilla::RoundUpPow2(reqSize);
166
33.4k
  }
167
33.4k
168
33.4k
  Header* header;
169
33.4k
  if (UsesAutoArrayBuffer() || !Copy::allowRealloc) {
170
0
    // Malloc() and copy
171
0
    header = static_cast<Header*>(ActualAlloc::Malloc(bytesToAlloc));
172
0
    if (!header) {
173
0
      return ActualAlloc::FailureResult();
174
0
    }
175
0
176
0
    Copy::MoveNonOverlappingRegionWithHeader(header, mHdr, Length(), aElemSize);
177
0
178
0
    if (!UsesAutoArrayBuffer()) {
179
0
      ActualAlloc::Free(mHdr);
180
0
    }
181
33.4k
  } else {
182
33.4k
    // Realloc() existing data
183
33.4k
    header = static_cast<Header*>(ActualAlloc::Realloc(mHdr, bytesToAlloc));
184
33.4k
    if (!header) {
185
0
      return ActualAlloc::FailureResult();
186
0
    }
187
33.4k
  }
188
33.4k
189
33.4k
  // How many elements can we fit in bytesToAlloc?
190
33.4k
  size_t newCapacity = (bytesToAlloc - sizeof(Header)) / aElemSize;
191
33.4k
  MOZ_ASSERT(newCapacity >= aCapacity, "Didn't enlarge the array enough!");
192
33.4k
  header->mCapacity = newCapacity;
193
33.4k
194
33.4k
  mHdr = header;
195
33.4k
196
33.4k
  return ActualAlloc::SuccessResult();
197
33.4k
}
nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Line
Count
Source
116
14.5M
{
117
14.5M
  // This should be the most common case so test this first
118
14.5M
  if (aCapacity <= mHdr->mCapacity) {
119
13.4M
    return ActualAlloc::SuccessResult();
120
13.4M
  }
121
1.01M
122
1.01M
  // If the requested memory allocation exceeds size_type(-1)/2, then
123
1.01M
  // our doubling algorithm may not be able to allocate it.
124
1.01M
  // Additionally, if it exceeds uint32_t(-1) then we couldn't fit in the
125
1.01M
  // Header::mCapacity member. Just bail out in cases like that.  We don't want
126
1.01M
  // to be allocating 2 GB+ arrays anyway.
127
1.01M
  if (!IsTwiceTheRequiredBytesRepresentableAsUint32(aCapacity, aElemSize)) {
128
0
    ActualAlloc::SizeTooBig((size_t)aCapacity * aElemSize);
129
0
    return ActualAlloc::FailureResult();
130
0
  }
131
1.01M
132
1.01M
  size_t reqSize = sizeof(Header) + aCapacity * aElemSize;
133
1.01M
134
1.01M
  if (mHdr == EmptyHdr()) {
135
985k
    // Malloc() new data
136
985k
    Header* header = static_cast<Header*>(ActualAlloc::Malloc(reqSize));
137
985k
    if (!header) {
138
0
      return ActualAlloc::FailureResult();
139
0
    }
140
985k
    header->mLength = 0;
141
985k
    header->mCapacity = aCapacity;
142
985k
    header->mIsAutoArray = 0;
143
985k
    mHdr = header;
144
985k
145
985k
    return ActualAlloc::SuccessResult();
146
985k
  }
147
33.4k
148
33.4k
  // We increase our capacity so that the allocated buffer grows exponentially,
149
33.4k
  // which gives us amortized O(1) appending. Below the threshold, we use
150
33.4k
  // powers-of-two. Above the threshold, we grow by at least 1.125, rounding up
151
33.4k
  // to the nearest MiB.
152
33.4k
  const size_t slowGrowthThreshold = 8 * 1024 * 1024;
153
33.4k
154
33.4k
  size_t bytesToAlloc;
155
33.4k
  if (reqSize >= slowGrowthThreshold) {
156
0
    size_t currSize = sizeof(Header) + Capacity() * aElemSize;
157
0
    size_t minNewSize = currSize + (currSize >> 3); // multiply by 1.125
158
0
    bytesToAlloc = reqSize > minNewSize ? reqSize : minNewSize;
159
0
160
0
    // Round up to the next multiple of MiB.
161
0
    const size_t MiB = 1 << 20;
162
0
    bytesToAlloc = MiB * ((bytesToAlloc + MiB - 1) / MiB);
163
33.4k
  } else {
164
33.4k
    // Round up to the next power of two.
165
33.4k
    bytesToAlloc = mozilla::RoundUpPow2(reqSize);
166
33.4k
  }
167
33.4k
168
33.4k
  Header* header;
169
33.4k
  if (UsesAutoArrayBuffer() || !Copy::allowRealloc) {
170
0
    // Malloc() and copy
171
0
    header = static_cast<Header*>(ActualAlloc::Malloc(bytesToAlloc));
172
0
    if (!header) {
173
0
      return ActualAlloc::FailureResult();
174
0
    }
175
0
176
0
    Copy::MoveNonOverlappingRegionWithHeader(header, mHdr, Length(), aElemSize);
177
0
178
0
    if (!UsesAutoArrayBuffer()) {
179
0
      ActualAlloc::Free(mHdr);
180
0
    }
181
33.4k
  } else {
182
33.4k
    // Realloc() existing data
183
33.4k
    header = static_cast<Header*>(ActualAlloc::Realloc(mHdr, bytesToAlloc));
184
33.4k
    if (!header) {
185
0
      return ActualAlloc::FailureResult();
186
0
    }
187
33.4k
  }
188
33.4k
189
33.4k
  // How many elements can we fit in bytesToAlloc?
190
33.4k
  size_t newCapacity = (bytesToAlloc - sizeof(Header)) / aElemSize;
191
33.4k
  MOZ_ASSERT(newCapacity >= aCapacity, "Didn't enlarge the array enough!");
192
33.4k
  header->mCapacity = newCapacity;
193
33.4k
194
33.4k
  mHdr = header;
195
33.4k
196
33.4k
  return ActualAlloc::SuccessResult();
197
33.4k
}
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Line
Count
Source
116
94
{
117
94
  // This should be the most common case so test this first
118
94
  if (aCapacity <= mHdr->mCapacity) {
119
12
    return ActualAlloc::SuccessResult();
120
12
  }
121
82
122
82
  // If the requested memory allocation exceeds size_type(-1)/2, then
123
82
  // our doubling algorithm may not be able to allocate it.
124
82
  // Additionally, if it exceeds uint32_t(-1) then we couldn't fit in the
125
82
  // Header::mCapacity member. Just bail out in cases like that.  We don't want
126
82
  // to be allocating 2 GB+ arrays anyway.
127
82
  if (!IsTwiceTheRequiredBytesRepresentableAsUint32(aCapacity, aElemSize)) {
128
0
    ActualAlloc::SizeTooBig((size_t)aCapacity * aElemSize);
129
0
    return ActualAlloc::FailureResult();
130
0
  }
131
82
132
82
  size_t reqSize = sizeof(Header) + aCapacity * aElemSize;
133
82
134
82
  if (mHdr == EmptyHdr()) {
135
79
    // Malloc() new data
136
79
    Header* header = static_cast<Header*>(ActualAlloc::Malloc(reqSize));
137
79
    if (!header) {
138
0
      return ActualAlloc::FailureResult();
139
0
    }
140
79
    header->mLength = 0;
141
79
    header->mCapacity = aCapacity;
142
79
    header->mIsAutoArray = 0;
143
79
    mHdr = header;
144
79
145
79
    return ActualAlloc::SuccessResult();
146
79
  }
147
3
148
3
  // We increase our capacity so that the allocated buffer grows exponentially,
149
3
  // which gives us amortized O(1) appending. Below the threshold, we use
150
3
  // powers-of-two. Above the threshold, we grow by at least 1.125, rounding up
151
3
  // to the nearest MiB.
152
3
  const size_t slowGrowthThreshold = 8 * 1024 * 1024;
153
3
154
3
  size_t bytesToAlloc;
155
3
  if (reqSize >= slowGrowthThreshold) {
156
0
    size_t currSize = sizeof(Header) + Capacity() * aElemSize;
157
0
    size_t minNewSize = currSize + (currSize >> 3); // multiply by 1.125
158
0
    bytesToAlloc = reqSize > minNewSize ? reqSize : minNewSize;
159
0
160
0
    // Round up to the next multiple of MiB.
161
0
    const size_t MiB = 1 << 20;
162
0
    bytesToAlloc = MiB * ((bytesToAlloc + MiB - 1) / MiB);
163
3
  } else {
164
3
    // Round up to the next power of two.
165
3
    bytesToAlloc = mozilla::RoundUpPow2(reqSize);
166
3
  }
167
3
168
3
  Header* header;
169
3
  if (UsesAutoArrayBuffer() || !Copy::allowRealloc) {
170
0
    // Malloc() and copy
171
0
    header = static_cast<Header*>(ActualAlloc::Malloc(bytesToAlloc));
172
0
    if (!header) {
173
0
      return ActualAlloc::FailureResult();
174
0
    }
175
0
176
0
    Copy::MoveNonOverlappingRegionWithHeader(header, mHdr, Length(), aElemSize);
177
0
178
0
    if (!UsesAutoArrayBuffer()) {
179
0
      ActualAlloc::Free(mHdr);
180
0
    }
181
3
  } else {
182
3
    // Realloc() existing data
183
3
    header = static_cast<Header*>(ActualAlloc::Realloc(mHdr, bytesToAlloc));
184
3
    if (!header) {
185
0
      return ActualAlloc::FailureResult();
186
0
    }
187
3
  }
188
3
189
3
  // How many elements can we fit in bytesToAlloc?
190
3
  size_t newCapacity = (bytesToAlloc - sizeof(Header)) / aElemSize;
191
3
  MOZ_ASSERT(newCapacity >= aCapacity, "Didn't enlarge the array enough!");
192
3
  header->mCapacity = newCapacity;
193
3
194
3
  mHdr = header;
195
3
196
3
  return ActualAlloc::SuccessResult();
197
3
}
nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::intl::Locale> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Line
Count
Source
116
3
{
117
3
  // This should be the most common case so test this first
118
3
  if (aCapacity <= mHdr->mCapacity) {
119
3
    return ActualAlloc::SuccessResult();
120
3
  }
121
0
122
0
  // If the requested memory allocation exceeds size_type(-1)/2, then
123
0
  // our doubling algorithm may not be able to allocate it.
124
0
  // Additionally, if it exceeds uint32_t(-1) then we couldn't fit in the
125
0
  // Header::mCapacity member. Just bail out in cases like that.  We don't want
126
0
  // to be allocating 2 GB+ arrays anyway.
127
0
  if (!IsTwiceTheRequiredBytesRepresentableAsUint32(aCapacity, aElemSize)) {
128
0
    ActualAlloc::SizeTooBig((size_t)aCapacity * aElemSize);
129
0
    return ActualAlloc::FailureResult();
130
0
  }
131
0
132
0
  size_t reqSize = sizeof(Header) + aCapacity * aElemSize;
133
0
134
0
  if (mHdr == EmptyHdr()) {
135
0
    // Malloc() new data
136
0
    Header* header = static_cast<Header*>(ActualAlloc::Malloc(reqSize));
137
0
    if (!header) {
138
0
      return ActualAlloc::FailureResult();
139
0
    }
140
0
    header->mLength = 0;
141
0
    header->mCapacity = aCapacity;
142
0
    header->mIsAutoArray = 0;
143
0
    mHdr = header;
144
0
145
0
    return ActualAlloc::SuccessResult();
146
0
  }
147
0
148
0
  // We increase our capacity so that the allocated buffer grows exponentially,
149
0
  // which gives us amortized O(1) appending. Below the threshold, we use
150
0
  // powers-of-two. Above the threshold, we grow by at least 1.125, rounding up
151
0
  // to the nearest MiB.
152
0
  const size_t slowGrowthThreshold = 8 * 1024 * 1024;
153
0
154
0
  size_t bytesToAlloc;
155
0
  if (reqSize >= slowGrowthThreshold) {
156
0
    size_t currSize = sizeof(Header) + Capacity() * aElemSize;
157
0
    size_t minNewSize = currSize + (currSize >> 3); // multiply by 1.125
158
0
    bytesToAlloc = reqSize > minNewSize ? reqSize : minNewSize;
159
0
160
0
    // Round up to the next multiple of MiB.
161
0
    const size_t MiB = 1 << 20;
162
0
    bytesToAlloc = MiB * ((bytesToAlloc + MiB - 1) / MiB);
163
0
  } else {
164
0
    // Round up to the next power of two.
165
0
    bytesToAlloc = mozilla::RoundUpPow2(reqSize);
166
0
  }
167
0
168
0
  Header* header;
169
0
  if (UsesAutoArrayBuffer() || !Copy::allowRealloc) {
170
0
    // Malloc() and copy
171
0
    header = static_cast<Header*>(ActualAlloc::Malloc(bytesToAlloc));
172
0
    if (!header) {
173
0
      return ActualAlloc::FailureResult();
174
0
    }
175
0
176
0
    Copy::MoveNonOverlappingRegionWithHeader(header, mHdr, Length(), aElemSize);
177
0
178
0
    if (!UsesAutoArrayBuffer()) {
179
0
      ActualAlloc::Free(mHdr);
180
0
    }
181
0
  } else {
182
0
    // Realloc() existing data
183
0
    header = static_cast<Header*>(ActualAlloc::Realloc(mHdr, bytesToAlloc));
184
0
    if (!header) {
185
0
      return ActualAlloc::FailureResult();
186
0
    }
187
0
  }
188
0
189
0
  // How many elements can we fit in bytesToAlloc?
190
0
  size_t newCapacity = (bytesToAlloc - sizeof(Header)) / aElemSize;
191
0
  MOZ_ASSERT(newCapacity >= aCapacity, "Didn't enlarge the array enough!");
192
0
  header->mCapacity = newCapacity;
193
0
194
0
  mHdr = header;
195
0
196
0
  return ActualAlloc::SuccessResult();
197
0
}
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ipc::StructuredCloneData> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::gfx::IntRegionTyped<mozilla::gfx::UnknownUnits> > >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::media::TimeIntervals> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<std::__1::function<mozilla::SupportChecker::CheckResult ()> > >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioSegment> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::StructuredCloneReadInfo> >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::StructuredCloneReadInfo> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::ClonedMessageData> >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::PaintedLayerData> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::EnsureCapacity<nsTArrayFallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::EnsureCapacity<nsTArrayInfallibleAllocator>(unsigned long, unsigned long)
198
199
// We don't need use Alloc template parameter specified here because failure to
200
// shrink the capacity will leave the array unchanged.
201
template<class Alloc, class Copy>
202
void
203
nsTArray_base<Alloc, Copy>::ShrinkCapacity(size_type aElemSize,
204
                                           size_t aElemAlign)
205
321k
{
206
321k
  if (mHdr == EmptyHdr() || UsesAutoArrayBuffer()) {
207
5.93k
    return;
208
5.93k
  }
209
315k
210
315k
  if (mHdr->mLength >= mHdr->mCapacity) { // should never be greater than...
211
0
    return;
212
0
  }
213
315k
214
315k
  size_type length = Length();
215
315k
216
315k
  if (IsAutoArray() && GetAutoArrayBuffer(aElemAlign)->mCapacity >= length) {
217
0
    Header* header = GetAutoArrayBuffer(aElemAlign);
218
0
219
0
    // Move the data, but don't copy the header to avoid overwriting mCapacity.
220
0
    header->mLength = length;
221
0
    Copy::MoveNonOverlappingRegion(header + 1, mHdr + 1, length, aElemSize);
222
0
223
0
    nsTArrayFallibleAllocator::Free(mHdr);
224
0
    mHdr = header;
225
0
    return;
226
0
  }
227
315k
228
315k
  if (length == 0) {
229
315k
    MOZ_ASSERT(!IsAutoArray(), "autoarray should have fit 0 elements");
230
315k
    nsTArrayFallibleAllocator::Free(mHdr);
231
315k
    mHdr = EmptyHdr();
232
315k
    return;
233
315k
  }
234
0
235
0
  size_type size = sizeof(Header) + length * aElemSize;
236
0
  void* ptr = nsTArrayFallibleAllocator::Realloc(mHdr, size);
237
0
  if (!ptr) {
238
0
    return;
239
0
  }
240
0
  mHdr = static_cast<Header*>(ptr);
241
0
  mHdr->mCapacity = length;
242
0
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::ShrinkCapacity(unsigned long, unsigned long)
Line
Count
Source
205
321k
{
206
321k
  if (mHdr == EmptyHdr() || UsesAutoArrayBuffer()) {
207
5.93k
    return;
208
5.93k
  }
209
315k
210
315k
  if (mHdr->mLength >= mHdr->mCapacity) { // should never be greater than...
211
0
    return;
212
0
  }
213
315k
214
315k
  size_type length = Length();
215
315k
216
315k
  if (IsAutoArray() && GetAutoArrayBuffer(aElemAlign)->mCapacity >= length) {
217
0
    Header* header = GetAutoArrayBuffer(aElemAlign);
218
0
219
0
    // Move the data, but don't copy the header to avoid overwriting mCapacity.
220
0
    header->mLength = length;
221
0
    Copy::MoveNonOverlappingRegion(header + 1, mHdr + 1, length, aElemSize);
222
0
223
0
    nsTArrayFallibleAllocator::Free(mHdr);
224
0
    mHdr = header;
225
0
    return;
226
0
  }
227
315k
228
315k
  if (length == 0) {
229
315k
    MOZ_ASSERT(!IsAutoArray(), "autoarray should have fit 0 elements");
230
315k
    nsTArrayFallibleAllocator::Free(mHdr);
231
315k
    mHdr = EmptyHdr();
232
315k
    return;
233
315k
  }
234
0
235
0
  size_type size = sizeof(Header) + length * aElemSize;
236
0
  void* ptr = nsTArrayFallibleAllocator::Realloc(mHdr, size);
237
0
  if (!ptr) {
238
0
    return;
239
0
  }
240
0
  mHdr = static_cast<Header*>(ptr);
241
0
  mHdr->mCapacity = length;
242
0
}
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<std::__1::function<mozilla::SupportChecker::CheckResult ()> > >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::PaintedLayerData> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::ShrinkCapacity(unsigned long, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::ShrinkCapacity(unsigned long, unsigned long)
243
244
template<class Alloc, class Copy>
245
template<typename ActualAlloc>
246
void
247
nsTArray_base<Alloc, Copy>::ShiftData(index_type aStart,
248
                                      size_type aOldLen, size_type aNewLen,
249
                                      size_type aElemSize, size_t aElemAlign)
250
321k
{
251
321k
  if (aOldLen == aNewLen) {
252
308k
    return;
253
308k
  }
254
13.1k
255
13.1k
  // Determine how many elements need to be shifted
256
13.1k
  size_type num = mHdr->mLength - (aStart + aOldLen);
257
13.1k
258
13.1k
  // Compute the resulting length of the array
259
13.1k
  mHdr->mLength += aNewLen - aOldLen;
260
13.1k
  if (mHdr->mLength == 0) {
261
128
    ShrinkCapacity(aElemSize, aElemAlign);
262
13.0k
  } else {
263
13.0k
    // Maybe nothing needs to be shifted
264
13.0k
    if (num == 0) {
265
13.0k
      return;
266
13.0k
    }
267
18
    // Perform shift (change units to bytes first)
268
18
    aStart *= aElemSize;
269
18
    aNewLen *= aElemSize;
270
18
    aOldLen *= aElemSize;
271
18
    char* baseAddr = reinterpret_cast<char*>(mHdr + 1) + aStart;
272
18
    Copy::MoveOverlappingRegion(baseAddr + aNewLen, baseAddr + aOldLen, num, aElemSize);
273
18
  }
274
13.1k
}
void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Line
Count
Source
250
321k
{
251
321k
  if (aOldLen == aNewLen) {
252
308k
    return;
253
308k
  }
254
13.1k
255
13.1k
  // Determine how many elements need to be shifted
256
13.1k
  size_type num = mHdr->mLength - (aStart + aOldLen);
257
13.1k
258
13.1k
  // Compute the resulting length of the array
259
13.1k
  mHdr->mLength += aNewLen - aOldLen;
260
13.1k
  if (mHdr->mLength == 0) {
261
128
    ShrinkCapacity(aElemSize, aElemAlign);
262
13.0k
  } else {
263
13.0k
    // Maybe nothing needs to be shifted
264
13.0k
    if (num == 0) {
265
13.0k
      return;
266
13.0k
    }
267
18
    // Perform shift (change units to bytes first)
268
18
    aStart *= aElemSize;
269
18
    aNewLen *= aElemSize;
270
18
    aOldLen *= aElemSize;
271
18
    char* baseAddr = reinterpret_cast<char*>(mHdr + 1) + aStart;
272
18
    Copy::MoveOverlappingRegion(baseAddr + aNewLen, baseAddr + aOldLen, num, aElemSize);
273
18
  }
274
13.1k
}
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::ShiftData<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::ShiftData<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::ShiftData<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::ShiftData<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::ShiftData<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JS::Value> > >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Movable> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: void nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::ShiftData<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
275
276
template<class Alloc, class Copy>
277
template<typename ActualAlloc>
278
void
279
nsTArray_base<Alloc, Copy>::SwapFromEnd(index_type aStart,
280
                                        size_type aCount,
281
                                        size_type aElemSize,
282
                                        size_t aElemAlign)
283
0
{
284
0
  // This method is part of the implementation of
285
0
  // nsTArray::SwapRemoveElement{s,}At. For more information, read the
286
0
  // documentation on that method.
287
0
  if (aCount == 0) {
288
0
    return;
289
0
  }
290
0
291
0
  // We are going to be removing aCount elements. Update our length to point to
292
0
  // the new end of the array.
293
0
  size_type oldLength = mHdr->mLength;
294
0
  mHdr->mLength -= aCount;
295
0
296
0
  if (mHdr->mLength == 0) {
297
0
    // If we have no elements remaining in the array, we can free our buffer.
298
0
    ShrinkCapacity(aElemSize, aElemAlign);
299
0
    return;
300
0
  }
301
0
302
0
  // Determine how many elements we need to move from the end of the array into
303
0
  // the now-removed section. This will either be the number of elements which
304
0
  // were removed (if there are more elements in the tail of the array), or the
305
0
  // entire tail of the array, whichever is smaller.
306
0
  size_type relocCount = std::min(aCount, mHdr->mLength - aStart);
307
0
  if (relocCount == 0) {
308
0
    return;
309
0
  }
310
0
311
0
  // Move the elements which are now stranded after the end of the array back
312
0
  // into the now-vacated memory.
313
0
  index_type sourceBytes = (oldLength - relocCount) * aElemSize;
314
0
  index_type destBytes = aStart * aElemSize;
315
0
316
0
  // Perform the final copy. This is guaranteed to be a non-overlapping copy
317
0
  // as our source contains only still-valid entries, and the destination
318
0
  // contains only invalid entries which need to be overwritten.
319
0
  MOZ_ASSERT(sourceBytes >= destBytes,
320
0
             "The source should be after the destination.");
321
0
  MOZ_ASSERT(sourceBytes - destBytes >= relocCount * aElemSize,
322
0
             "The range should be nonoverlapping");
323
0
324
0
  char* baseAddr = reinterpret_cast<char*>(mHdr + 1);
325
0
  Copy::MoveNonOverlappingRegion(baseAddr + destBytes,
326
0
                                 baseAddr + sourceBytes,
327
0
                                 relocCount,
328
0
                                 aElemSize);
329
0
}
330
331
template<class Alloc, class Copy>
332
template<typename ActualAlloc>
333
bool
334
nsTArray_base<Alloc, Copy>::InsertSlotsAt(index_type aIndex, size_type aCount,
335
                                          size_type aElemSize,
336
                                          size_t aElemAlign)
337
0
{
338
0
  if (MOZ_UNLIKELY(aIndex > Length())) {
339
0
    InvalidArrayIndex_CRASH(aIndex, Length());
340
0
  }
341
0
342
0
  size_type newLen = Length() + aCount;
343
0
344
0
  EnsureCapacity<ActualAlloc>(newLen, aElemSize);
345
0
346
0
  // Check for out of memory conditions
347
0
  if (Capacity() < newLen) {
348
0
    return false;
349
0
  }
350
0
351
0
  // Move the existing elements as needed.  Note that this will
352
0
  // change our mLength, so no need to call IncrementLength.
353
0
  ShiftData<ActualAlloc>(aIndex, 0, aCount, aElemSize, aElemAlign);
354
0
355
0
  return true;
356
0
}
Unexecuted instantiation: bool nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::InsertSlotsAt<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::InsertSlotsAt<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::InsertSlotsAt<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::InsertSlotsAt<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<JS::Heap<JSObject*> > >::InsertSlotsAt<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioBlock> >::InsertSlotsAt<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::InsertSlotsAt<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::InsertSlotsAt<nsTArrayFallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::InsertSlotsAt<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<TestTArray::Copyable> >::InsertSlotsAt<nsTArrayInfallibleAllocator>(unsigned long, unsigned long, unsigned long, unsigned long)
357
358
// nsTArray_base::IsAutoArrayRestorer is an RAII class which takes
359
// |nsTArray_base &array| in its constructor.  When it's destructed, it ensures
360
// that
361
//
362
//   * array.mIsAutoArray has the same value as it did when we started, and
363
//   * if array has an auto buffer and mHdr would otherwise point to
364
//     sEmptyTArrayHeader, array.mHdr points to array's auto buffer.
365
366
template<class Alloc, class Copy>
367
nsTArray_base<Alloc, Copy>::IsAutoArrayRestorer::IsAutoArrayRestorer(
368
      nsTArray_base<Alloc, Copy>& aArray,
369
      size_t aElemAlign)
370
  : mArray(aArray)
371
  , mElemAlign(aElemAlign)
372
  , mIsAuto(aArray.IsAutoArray())
373
42
{
374
42
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>&, unsigned long)
Line
Count
Source
373
42
{
374
42
}
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >&, unsigned long)
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >&, unsigned long)
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::IsAutoArrayRestorer::IsAutoArrayRestorer(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >&, unsigned long)
375
376
template<class Alloc, class Copy>
377
nsTArray_base<Alloc, Copy>::IsAutoArrayRestorer::~IsAutoArrayRestorer()
378
42
{
379
42
  // Careful: We don't want to set mIsAutoArray = 1 on sEmptyTArrayHeader.
380
42
  if (mIsAuto && mArray.mHdr == mArray.EmptyHdr()) {
381
0
    // Call GetAutoArrayBufferUnsafe() because GetAutoArrayBuffer() asserts
382
0
    // that mHdr->mIsAutoArray is true, which surely isn't the case here.
383
0
    mArray.mHdr = mArray.GetAutoArrayBufferUnsafe(mElemAlign);
384
0
    mArray.mHdr->mLength = 0;
385
42
  } else if (mArray.mHdr != mArray.EmptyHdr()) {
386
18
    mArray.mHdr->mIsAutoArray = mIsAuto;
387
18
  }
388
42
}
nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Line
Count
Source
378
42
{
379
42
  // Careful: We don't want to set mIsAutoArray = 1 on sEmptyTArrayHeader.
380
42
  if (mIsAuto && mArray.mHdr == mArray.EmptyHdr()) {
381
0
    // Call GetAutoArrayBufferUnsafe() because GetAutoArrayBuffer() asserts
382
0
    // that mHdr->mIsAutoArray is true, which surely isn't the case here.
383
0
    mArray.mHdr = mArray.GetAutoArrayBufferUnsafe(mElemAlign);
384
0
    mArray.mHdr->mLength = 0;
385
42
  } else if (mArray.mHdr != mArray.EmptyHdr()) {
386
18
    mArray.mHdr->mIsAutoArray = mIsAuto;
387
18
  }
388
42
}
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
Unexecuted instantiation: nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::IsAutoArrayRestorer::~IsAutoArrayRestorer()
389
390
template<class Alloc, class Copy>
391
template<typename ActualAlloc, class Allocator>
392
typename ActualAlloc::ResultTypeProxy
393
nsTArray_base<Alloc, Copy>::SwapArrayElements(nsTArray_base<Allocator,
394
                                                            Copy>& aOther,
395
                                              size_type aElemSize,
396
                                              size_t aElemAlign)
397
21
{
398
21
399
21
  // EnsureNotUsingAutoArrayBuffer will set mHdr = sEmptyTArrayHeader even if we
400
21
  // have an auto buffer.  We need to point mHdr back to our auto buffer before
401
21
  // we return, otherwise we'll forget that we have an auto buffer at all!
402
21
  // IsAutoArrayRestorer takes care of this for us.
403
21
404
21
  IsAutoArrayRestorer ourAutoRestorer(*this, aElemAlign);
405
21
  typename nsTArray_base<Allocator, Copy>::IsAutoArrayRestorer
406
21
    otherAutoRestorer(aOther, aElemAlign);
407
21
408
21
  // If neither array uses an auto buffer which is big enough to store the
409
21
  // other array's elements, then ensure that both arrays use malloc'ed storage
410
21
  // and swap their mHdr pointers.
411
21
  if ((!UsesAutoArrayBuffer() || Capacity() < aOther.Length()) &&
412
21
      (!aOther.UsesAutoArrayBuffer() || aOther.Capacity() < Length())) {
413
18
414
18
    if (!EnsureNotUsingAutoArrayBuffer<ActualAlloc>(aElemSize) ||
415
18
        !aOther.template EnsureNotUsingAutoArrayBuffer<ActualAlloc>(aElemSize)) {
416
0
      return ActualAlloc::FailureResult();
417
0
    }
418
18
419
18
    Header* temp = mHdr;
420
18
    mHdr = aOther.mHdr;
421
18
    aOther.mHdr = temp;
422
18
423
18
    return ActualAlloc::SuccessResult();
424
18
  }
425
3
426
3
  // Swap the two arrays by copying, since at least one is using an auto
427
3
  // buffer which is large enough to hold all of the aOther's elements.  We'll
428
3
  // copy the shorter array into temporary storage.
429
3
  //
430
3
  // (We could do better than this in some circumstances.  Suppose we're
431
3
  // swapping arrays X and Y.  X has space for 2 elements in its auto buffer,
432
3
  // but currently has length 4, so it's using malloc'ed storage.  Y has length
433
3
  // 2.  When we swap X and Y, we don't need to use a temporary buffer; we can
434
3
  // write Y straight into X's auto buffer, write X's malloc'ed buffer on top
435
3
  // of Y, and then switch X to using its auto buffer.)
436
3
437
3
  if (!ActualAlloc::Successful(EnsureCapacity<ActualAlloc>(aOther.Length(), aElemSize)) ||
438
3
      !Allocator::Successful(aOther.template EnsureCapacity<Allocator>(Length(), aElemSize))) {
439
0
    return ActualAlloc::FailureResult();
440
0
  }
441
3
442
3
  // The EnsureCapacity calls above shouldn't have caused *both* arrays to
443
3
  // switch from their auto buffers to malloc'ed space.
444
3
  MOZ_ASSERT(UsesAutoArrayBuffer() || aOther.UsesAutoArrayBuffer(),
445
3
             "One of the arrays should be using its auto buffer.");
446
3
447
3
  size_type smallerLength = XPCOM_MIN(Length(), aOther.Length());
448
3
  size_type largerLength = XPCOM_MAX(Length(), aOther.Length());
449
3
  void* smallerElements;
450
3
  void* largerElements;
451
3
  if (Length() <= aOther.Length()) {
452
3
    smallerElements = Hdr() + 1;
453
3
    largerElements = aOther.Hdr() + 1;
454
3
  } else {
455
0
    smallerElements = aOther.Hdr() + 1;
456
0
    largerElements = Hdr() + 1;
457
0
  }
458
3
459
3
  // Allocate temporary storage for the smaller of the two arrays.  We want to
460
3
  // allocate this space on the stack, if it's not too large.  Sounds like a
461
3
  // job for AutoTArray!  (One of the two arrays we're swapping is using an
462
3
  // auto buffer, so we're likely not allocating a lot of space here.  But one
463
3
  // could, in theory, allocate a huge AutoTArray on the heap.)
464
3
  AutoTArray<uint8_t, 64 * sizeof(void*)> temp;
465
3
  if (!ActualAlloc::Successful(temp.template EnsureCapacity<ActualAlloc>(smallerLength * aElemSize, sizeof(uint8_t)))) {
466
0
    return ActualAlloc::FailureResult();
467
0
  }
468
3
469
3
  Copy::MoveNonOverlappingRegion(temp.Elements(), smallerElements, smallerLength, aElemSize);
470
3
  Copy::MoveNonOverlappingRegion(smallerElements, largerElements, largerLength, aElemSize);
471
3
  Copy::MoveNonOverlappingRegion(largerElements, temp.Elements(), smallerLength, aElemSize);
472
3
473
3
  // Swap the arrays' lengths.
474
3
  MOZ_ASSERT((aOther.Length() == 0 || mHdr != EmptyHdr()) &&
475
3
             (Length() == 0 || aOther.mHdr != EmptyHdr()),
476
3
             "Don't set sEmptyTArrayHeader's length.");
477
3
  size_type tempLength = Length();
478
3
479
3
  // Avoid writing to EmptyHdr, since it can trigger false
480
3
  // positives with TSan.
481
3
  if (mHdr != EmptyHdr()) {
482
3
    mHdr->mLength = aOther.Length();
483
3
  }
484
3
  if (aOther.mHdr != EmptyHdr()) {
485
3
    aOther.mHdr->mLength = tempLength;
486
3
  }
487
3
488
3
  return ActualAlloc::SuccessResult();
489
3
}
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >&, unsigned long, unsigned long)
nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>&, unsigned long, unsigned long)
Line
Count
Source
397
21
{
398
21
399
21
  // EnsureNotUsingAutoArrayBuffer will set mHdr = sEmptyTArrayHeader even if we
400
21
  // have an auto buffer.  We need to point mHdr back to our auto buffer before
401
21
  // we return, otherwise we'll forget that we have an auto buffer at all!
402
21
  // IsAutoArrayRestorer takes care of this for us.
403
21
404
21
  IsAutoArrayRestorer ourAutoRestorer(*this, aElemAlign);
405
21
  typename nsTArray_base<Allocator, Copy>::IsAutoArrayRestorer
406
21
    otherAutoRestorer(aOther, aElemAlign);
407
21
408
21
  // If neither array uses an auto buffer which is big enough to store the
409
21
  // other array's elements, then ensure that both arrays use malloc'ed storage
410
21
  // and swap their mHdr pointers.
411
21
  if ((!UsesAutoArrayBuffer() || Capacity() < aOther.Length()) &&
412
21
      (!aOther.UsesAutoArrayBuffer() || aOther.Capacity() < Length())) {
413
18
414
18
    if (!EnsureNotUsingAutoArrayBuffer<ActualAlloc>(aElemSize) ||
415
18
        !aOther.template EnsureNotUsingAutoArrayBuffer<ActualAlloc>(aElemSize)) {
416
0
      return ActualAlloc::FailureResult();
417
0
    }
418
18
419
18
    Header* temp = mHdr;
420
18
    mHdr = aOther.mHdr;
421
18
    aOther.mHdr = temp;
422
18
423
18
    return ActualAlloc::SuccessResult();
424
18
  }
425
3
426
3
  // Swap the two arrays by copying, since at least one is using an auto
427
3
  // buffer which is large enough to hold all of the aOther's elements.  We'll
428
3
  // copy the shorter array into temporary storage.
429
3
  //
430
3
  // (We could do better than this in some circumstances.  Suppose we're
431
3
  // swapping arrays X and Y.  X has space for 2 elements in its auto buffer,
432
3
  // but currently has length 4, so it's using malloc'ed storage.  Y has length
433
3
  // 2.  When we swap X and Y, we don't need to use a temporary buffer; we can
434
3
  // write Y straight into X's auto buffer, write X's malloc'ed buffer on top
435
3
  // of Y, and then switch X to using its auto buffer.)
436
3
437
3
  if (!ActualAlloc::Successful(EnsureCapacity<ActualAlloc>(aOther.Length(), aElemSize)) ||
438
3
      !Allocator::Successful(aOther.template EnsureCapacity<Allocator>(Length(), aElemSize))) {
439
0
    return ActualAlloc::FailureResult();
440
0
  }
441
3
442
3
  // The EnsureCapacity calls above shouldn't have caused *both* arrays to
443
3
  // switch from their auto buffers to malloc'ed space.
444
3
  MOZ_ASSERT(UsesAutoArrayBuffer() || aOther.UsesAutoArrayBuffer(),
445
3
             "One of the arrays should be using its auto buffer.");
446
3
447
3
  size_type smallerLength = XPCOM_MIN(Length(), aOther.Length());
448
3
  size_type largerLength = XPCOM_MAX(Length(), aOther.Length());
449
3
  void* smallerElements;
450
3
  void* largerElements;
451
3
  if (Length() <= aOther.Length()) {
452
3
    smallerElements = Hdr() + 1;
453
3
    largerElements = aOther.Hdr() + 1;
454
3
  } else {
455
0
    smallerElements = aOther.Hdr() + 1;
456
0
    largerElements = Hdr() + 1;
457
0
  }
458
3
459
3
  // Allocate temporary storage for the smaller of the two arrays.  We want to
460
3
  // allocate this space on the stack, if it's not too large.  Sounds like a
461
3
  // job for AutoTArray!  (One of the two arrays we're swapping is using an
462
3
  // auto buffer, so we're likely not allocating a lot of space here.  But one
463
3
  // could, in theory, allocate a huge AutoTArray on the heap.)
464
3
  AutoTArray<uint8_t, 64 * sizeof(void*)> temp;
465
3
  if (!ActualAlloc::Successful(temp.template EnsureCapacity<ActualAlloc>(smallerLength * aElemSize, sizeof(uint8_t)))) {
466
0
    return ActualAlloc::FailureResult();
467
0
  }
468
3
469
3
  Copy::MoveNonOverlappingRegion(temp.Elements(), smallerElements, smallerLength, aElemSize);
470
3
  Copy::MoveNonOverlappingRegion(smallerElements, largerElements, largerLength, aElemSize);
471
3
  Copy::MoveNonOverlappingRegion(largerElements, temp.Elements(), smallerLength, aElemSize);
472
3
473
3
  // Swap the arrays' lengths.
474
3
  MOZ_ASSERT((aOther.Length() == 0 || mHdr != EmptyHdr()) &&
475
3
             (Length() == 0 || aOther.mHdr != EmptyHdr()),
476
3
             "Don't set sEmptyTArrayHeader's length.");
477
3
  size_type tempLength = Length();
478
3
479
3
  // Avoid writing to EmptyHdr, since it can trigger false
480
3
  // positives with TSan.
481
3
  if (mHdr != EmptyHdr()) {
482
3
    mHdr->mLength = aOther.Length();
483
3
  }
484
3
  if (aOther.mHdr != EmptyHdr()) {
485
3
    aOther.mHdr->mLength = tempLength;
486
3
  }
487
3
488
3
  return ActualAlloc::SuccessResult();
489
3
}
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::SwapArrayElements<nsTArrayFallibleAllocator, nsTArrayFallibleAllocator>(nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::SwapArrayElements<nsTArrayFallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayFallibleAllocator>(nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayFallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::SwapArrayElements<nsTArrayFallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >&, unsigned long, unsigned long)
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >&, unsigned long, unsigned long)
Unexecuted instantiation: nsTArrayInfallibleAllocator::ResultTypeProxy nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::SwapArrayElements<nsTArrayInfallibleAllocator, nsTArrayInfallibleAllocator>(nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >&, unsigned long, unsigned long)
490
491
template<class Alloc, class Copy>
492
template<typename ActualAlloc>
493
bool
494
nsTArray_base<Alloc, Copy>::EnsureNotUsingAutoArrayBuffer(size_type aElemSize)
495
36
{
496
36
  if (UsesAutoArrayBuffer()) {
497
0
498
0
    // If you call this on a 0-length array, we'll set that array's mHdr to
499
0
    // sEmptyTArrayHeader, in flagrant violation of the AutoTArray invariants.
500
0
    // It's up to you to set it back!  (If you don't, the AutoTArray will
501
0
    // forget that it has an auto buffer.)
502
0
    if (Length() == 0) {
503
0
      mHdr = EmptyHdr();
504
0
      return true;
505
0
    }
506
0
507
0
    size_type size = sizeof(Header) + Length() * aElemSize;
508
0
509
0
    Header* header = static_cast<Header*>(ActualAlloc::Malloc(size));
510
0
    if (!header) {
511
0
      return false;
512
0
    }
513
0
514
0
    Copy::MoveNonOverlappingRegionWithHeader(header, mHdr, Length(), aElemSize);
515
0
    header->mCapacity = Length();
516
0
    mHdr = header;
517
0
  }
518
36
519
36
  return true;
520
36
}
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<regiondetails::Band> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Line
Count
Source
495
36
{
496
36
  if (UsesAutoArrayBuffer()) {
497
0
498
0
    // If you call this on a 0-length array, we'll set that array's mHdr to
499
0
    // sEmptyTArrayHeader, in flagrant violation of the AutoTArray invariants.
500
0
    // It's up to you to set it back!  (If you don't, the AutoTArray will
501
0
    // forget that it has an auto buffer.)
502
0
    if (Length() == 0) {
503
0
      mHdr = EmptyHdr();
504
0
      return true;
505
0
    }
506
0
507
0
    size_type size = sizeof(Header) + Length() * aElemSize;
508
0
509
0
    Header* header = static_cast<Header*>(ActualAlloc::Malloc(size));
510
0
    if (!header) {
511
0
      return false;
512
0
    }
513
0
514
0
    Copy::MoveNonOverlappingRegionWithHeader(header, mHdr, Length(), aElemSize);
515
0
    header->mCapacity = Length();
516
0
    mHdr = header;
517
0
  }
518
36
519
36
  return true;
520
36
}
Unexecuted instantiation: bool nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::EnsureNotUsingAutoArrayBuffer<nsTArrayFallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithMemutils>::EnsureNotUsingAutoArrayBuffer<nsTArrayFallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::ObjectStoreCursorResponse> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::AudioChunk> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::layers::TileClient> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithMemutils>::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<nsStyleFilter> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayFallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::EnsureNotUsingAutoArrayBuffer<nsTArrayFallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo> >::EnsureNotUsingAutoArrayBuffer<nsTArrayFallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 2ul> > >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: Unified_cpp_mozapps_extensions0.cpp:bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<mozilla::(anonymous namespace)::ContentEntry> >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)
Unexecuted instantiation: bool nsTArray_base<nsTArrayInfallibleAllocator, nsTArray_CopyWithConstructors<AutoTArray<nsTString<char>, 3ul> > >::EnsureNotUsingAutoArrayBuffer<nsTArrayInfallibleAllocator>(unsigned long)