Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
skia_private::TArray< T, MEM_MOVE > Class Template Reference

#include <SkTArray.h>

Inheritance diagram for skia_private::TArray< T, MEM_MOVE >:
skia_private::STArray< 2, std::unique_ptr< Expression > > skia_private::STArray< 1, Circle, true > skia_private::STArray< 1, RRect, true > skia_private::STArray< 1, Ellipse, true > skia_private::STArray< sk_sp< GrManagedResource > > skia_private::STArray< sk_sp< GrRecycledResource > > skia_private::STArray< sk_sp< const GrBuffer > > skia_private::STArray< 4, D3D12_RESOURCE_BARRIER > skia_private::STArray< 32, GrD3DDescriptorHeap::CPUHandle > skia_private::STArray< 4, std::unique_ptr< GrD3DDirectCommandList > > skia_private::STArray< 4, sk_sp< GrD3DRootSignature > > skia_private::STArray< 2, sk_sp< GrD3DCommandSignature > > skia_private::STArray< 1, std::unique_ptr< GrFragmentProcessor >, true > skia_private::STArray< 4, GrFragmentProcessor::ProgramImpl *, true > skia_private::STArray< 16, AttribArrayState, true > skia_private::STArray< kPrealloc, SkString > skia_private::STArray< 2, std::unique_ptr< Statement > > skia_private::STArray< 1, SkString > skia_private::STArray< 4, SubmittedProc > skia_private::STArray< kInitialTrackedResourcesCount, sk_sp< const GrManagedResource > > skia_private::STArray< kInitialTrackedResourcesCount, sk_sp< const GrBuffer > > skia_private::STArray< 16, gr_sp< const GrSurface > > skia_private::STArray< kPreAllocSize, uint32_t, true > skia_private::STArray< 1, sk_sp< GrSurfaceProxy > > skia_private::STArray< 1, GrRenderTask *, true > skia_private::STArray< kMaxAttribCount, SkMeshSpecification::Attribute > skia_private::STArray< 4, Resolve > skia_private::STArray< 1, skgpu::VulkanYcbcrConversionInfo > skia_private::STArray< sk_sp< const GrManagedResource > > skia_private::STArray< gr_sp< const GrRecycledResource > > skia_private::STArray< 16, sk_sp< const GrBuffer > > skia_private::STArray< 1, VkBufferMemoryBarrier > skia_private::STArray< 2, VkImageMemoryBarrier > skia_private::STArray< 4, std::unique_ptr< GrVkSecondaryCommandBuffer >, true > skia_private::STArray< 4, uint32_t > skia_private::STArray< 4, const GrVkSampler * > skia_private::STArray< 1, GrVkSemaphore::Resource * > skia_private::STArray< 4, CompatibleRenderPassSet > skia_private::STArray< 4, GrVkCommandPool *, true > skia_private::STArray< 4, std::unique_ptr< GrVkDescriptorSetManager > > skia_private::STArray< 4, GrVkRenderPass * > skia_private::STArray< 4, ImVec2, true > skia_private::STArray< 1, sk_sp< SkImageFilter > > skia_private::STArray< SkDCubic::kMaxIntersections *2, SkClosestRecord, true > skia_private::STArray< 4, SkPMColor4f > skia_private::STArray< 4, float > skia_private::STArray< 2, SkColor4f > skia_private::STArray< 16, SkColor4f > skia_private::STArray< 16, SkScalar > skia_private::STArray< 2, sk_sp< SkImageFilter >, true > skia_private::STArray< 16, Scope, true > skia_private::STArray< 16, bool, true > skia_private::STArray< 2, SkRuntimeEffect::ChildPtr > skia_private::STArray< 4, ClipState > skia_private::STArray< 4, SkPoint > skia_private::STArray< 4, uint8_t > skia_private::STArray< 2, SkScalar > skia_private::STArray< 2, SkRasterPipeline_MemoryCtxInfo > skia_private::STArray< 8, int32_t > skia_private::STArray< 4, int8_t > skia_private::STArray< 1, sk_sp< SkSVGNode >, true > skia_private::STArray< 128, char, true > skia_private::STArray< 128, PositionAdjustment, true > skia_private::STArray< kMinItems, skgpu::BulkUsePlotUpdater::PlotData, true > skia_private::STArray< 4, Plane > skia_private::STArray< 4, sk_sp< skgpu::ganesh::AtlasRenderTask > > skia_private::STArray< 25, OpChain > skia_private::STArray< 2, const GrProgramInfo * > skia_private::STArray< kPreAllocCount, sk_sp< skgpu::ganesh::PathRenderer > > skia_private::STArray< 1, GrVertexChunk > skia_private::STArray< sk_sp< skgpu::graphite::Resource > > skia_private::STArray< gr_sp< skgpu::graphite::Resource > > skia_private::STArray< 1, std::unique_ptr< DispatchGroup > > skia_private::STArray< 1, std::unique_ptr< DrawPass > > skia_private::STArray< 1, skgpu::graphite::BufferTextureCopyData > skia_private::STArray< 1, skgpu::graphite::UploadInstance > skia_private::STArray< 1, VkSemaphore > skia_private::STArray< 2, std::unique_ptr< const skgpu::graphite::VulkanImageView > > skia_private::STArray< 4, skia::textlayout::TextStyle, true > skia_private::STArray< 4, skia::textlayout::Block, true > skia_private::STArray< 4, skia::textlayout::Placeholder, true > skia_private::STArray< 64, SkGlyphID, true > skia_private::STArray< 64, SkPoint, true > skia_private::STArray< 64, uint32_t, true > skia_private::STArray< 1, size_t, true > skia_private::STArray< 1, SampledFilterResult > skia_private::STArray< 1, sk_sp< SkShader > > skia_private::STArray< 1, sk_sp< sktext::gpu::TextBlob > > skia_private::STArray< Nreq, T, MEM_MOVE >

Public Types

using value_type = T
 

Public Member Functions

 TArray ()
 
 TArray (int reserveCount)
 
 TArray (const TArray &that)
 
 TArray (TArray &&that)
 
 TArray (const T *array, int count)
 
 TArray (std::initializer_list< T > data)
 
TArrayoperator= (const TArray &that)
 
TArrayoperator= (TArray &&that)
 
 ~TArray ()
 
void reset (int n)
 
void reset (const T *array, int count)
 
void reserve (int n)
 
void reserve_exact (int n)
 
void removeShuffle (int n)
 
bool empty () const
 
Tpush_back ()
 
Tpush_back (const T &t)
 
Tpush_back (T &&t)
 
template<typename... Args>
Templace_back (Args &&... args)
 
Tpush_back_n (int n)
 
Tpush_back_n (int n, const T &t)
 
Tpush_back_n (int n, const T t[])
 
Tmove_back_n (int n, T *t)
 
void pop_back ()
 
void pop_back_n (int n)
 
void resize_back (int newCount)
 
void swap (TArray &that)
 
void move_back (TArray &that)
 
Tbegin ()
 
const Tbegin () const
 
Tend ()
 
const Tend () const
 
Tdata ()
 
const Tdata () const
 
int size () const
 
size_t size_bytes () const
 
void resize (size_t count)
 
void clear ()
 
void shrink_to_fit ()
 
Toperator[] (int i)
 
const Toperator[] (int i) const
 
Tat (int i)
 
const Tat (int i) const
 
Tfront ()
 
const Tfront () const
 
Tback ()
 
const Tback () const
 
TfromBack (int i)
 
const TfromBack (int i) const
 
bool operator== (const TArray< T, MEM_MOVE > &right) const
 
bool operator!= (const TArray< T, MEM_MOVE > &right) const
 
int capacity () const
 

Protected Member Functions

template<int InitialCapacity>
 TArray (SkAlignedSTStorage< InitialCapacity, T > *storage, int size=0)
 
template<int InitialCapacity>
 TArray (const T *array, int size, SkAlignedSTStorage< InitialCapacity, T > *storage)
 

Detailed Description

template<typename T, bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
class skia_private::TArray< T, MEM_MOVE >

TArray<T> implements a typical, mostly std::vector-like array. Each T will be default-initialized on allocation, and ~T will be called on destruction.

MEM_MOVE controls the behavior when a T needs to be moved (e.g. when the array is resized)

Definition at line 40 of file SkTArray.h.

Member Typedef Documentation

◆ value_type

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
using skia_private::TArray< T, MEM_MOVE >::value_type = T

Definition at line 42 of file SkTArray.h.

Constructor & Destructor Documentation

◆ TArray() [1/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::TArray ( )
inline

Creates an empty array with no initial storage

Definition at line 47 of file SkTArray.h.

47: fOwnMemory(true), fCapacity{0} {}

◆ TArray() [2/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::TArray ( int  reserveCount)
inlineexplicit

Creates an empty array that will preallocate space for reserveCount elements.

Definition at line 52 of file SkTArray.h.

52: TArray() { this->reserve_exact(reserveCount); }
void reserve_exact(int n)
Definition SkTArray.h:176

◆ TArray() [3/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::TArray ( const TArray< T, MEM_MOVE > &  that)
inline

Copies one array to another. The new array will be heap allocated.

Definition at line 57 of file SkTArray.h.

57: TArray(that.fData, that.fSize) {}

◆ TArray() [4/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::TArray ( TArray< T, MEM_MOVE > &&  that)
inline

Definition at line 59 of file SkTArray.h.

59 {
60 if (that.fOwnMemory) {
61 this->setData(that);
62 that.setData({});
63 } else {
64 this->initData(that.fSize);
65 that.move(fData);
66 }
67 this->changeSize(that.fSize);
68 that.changeSize(0);
69 }

◆ TArray() [5/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::TArray ( const T array,
int  count 
)
inline

Creates a TArray by copying contents of a standard C array. The new array will be heap allocated. Be careful not to use this constructor when you really want the (void*, int) version.

Definition at line 76 of file SkTArray.h.

76 {
77 this->initData(count);
78 this->copy(array);
79 }
int count
Definition copy.py:1

◆ TArray() [6/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::TArray ( std::initializer_list< T data)
inline

Creates a TArray by copying contents of an initializer list.

Definition at line 84 of file SkTArray.h.

84: TArray(data.begin(), data.size()) {}

◆ ~TArray()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
skia_private::TArray< T, MEM_MOVE >::~TArray ( )
inline

Definition at line 128 of file SkTArray.h.

128 {
129 this->destroyAll();
130 this->unpoison();
131 if (fOwnMemory) {
132 sk_free(fData);
133 }
134 }
SK_API void sk_free(void *)

◆ TArray() [7/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
template<int InitialCapacity>
skia_private::TArray< T, MEM_MOVE >::TArray ( SkAlignedSTStorage< InitialCapacity, T > *  storage,
int  size = 0 
)
inlineprotected

Definition at line 521 of file SkTArray.h.

521 {
522 static_assert(InitialCapacity >= 0);
523 SkASSERT(size >= 0);
524 SkASSERT(storage->get() != nullptr);
525 if (size > InitialCapacity) {
526 this->initData(size);
527 } else {
528 this->setDataFromBytes(*storage);
529 this->changeSize(size);
530
531 // setDataFromBytes always sets fOwnMemory to true, but we are actually using static
532 // storage here, which shouldn't ever be freed.
533 fOwnMemory = false;
534 }
535 }
#define SkASSERT(cond)
Definition SkAssert.h:116
int size() const
Definition SkTArray.h:416

◆ TArray() [8/8]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
template<int InitialCapacity>
skia_private::TArray< T, MEM_MOVE >::TArray ( const T array,
int  size,
SkAlignedSTStorage< InitialCapacity, T > *  storage 
)
inlineprotected

Definition at line 540 of file SkTArray.h.

541 : TArray{storage, size} {
542 this->copy(array);
543 }

Member Function Documentation

◆ at() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::at ( int  i)
inline

Definition at line 456 of file SkTArray.h.

456{ return (*this)[i]; }

◆ at() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T & skia_private::TArray< T, MEM_MOVE >::at ( int  i) const
inline

Definition at line 457 of file SkTArray.h.

457{ return (*this)[i]; }

◆ back() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::back ( )
inline

equivalent to operator[](size() - 1)

Definition at line 475 of file SkTArray.h.

475 {
477 return fData[fSize - 1];
478 }
SK_API void sk_collection_not_empty(bool empty)
Definition SkAssert.h:175
bool empty() const
Definition SkTArray.h:194

◆ back() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T & skia_private::TArray< T, MEM_MOVE >::back ( ) const
inline

Definition at line 480 of file SkTArray.h.

480 {
482 return fData[fSize - 1];
483 }

◆ begin() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::begin ( )
inline

Definition at line 393 of file SkTArray.h.

393 {
394 return fData;
395 }

◆ begin() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T * skia_private::TArray< T, MEM_MOVE >::begin ( ) const
inline

Definition at line 396 of file SkTArray.h.

396 {
397 return fData;
398 }

◆ capacity()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
int skia_private::TArray< T, MEM_MOVE >::capacity ( ) const
inline

Definition at line 513 of file SkTArray.h.

513 {
514 return fCapacity;
515 }

◆ clear()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::clear ( )
inline

Definition at line 420 of file SkTArray.h.

420 {
421 this->destroyAll();
422 this->changeSize(0);
423 }

◆ data() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::data ( )
inline

Definition at line 414 of file SkTArray.h.

414{ return fData; }

◆ data() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T * skia_private::TArray< T, MEM_MOVE >::data ( ) const
inline

Definition at line 415 of file SkTArray.h.

415{ return fData; }

◆ emplace_back()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
template<typename... Args>
T & skia_private::TArray< T, MEM_MOVE >::emplace_back ( Args &&...  args)
inline

Constructs a new T at the back of this array, returning it by reference.

Definition at line 243 of file SkTArray.h.

243 {
244 this->unpoison();
245 T* newT;
246 if (this->capacity() > fSize) SK_LIKELY {
247 // Emplace the new element in directly.
248 newT = new (fData + fSize) T(std::forward<Args>(args)...);
249 } else {
250 newT = this->growAndConstructAtEnd(std::forward<Args>(args)...);
251 }
252
253 this->changeSize(fSize + 1);
254 return *newT;
255 }
#define SK_LIKELY
Definition SkAssert.h:27
int capacity() const
Definition SkTArray.h:513
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define T

◆ empty()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
bool skia_private::TArray< T, MEM_MOVE >::empty ( ) const
inline

Definition at line 194 of file SkTArray.h.

194{ return fSize == 0; }

◆ end() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::end ( )
inline

Definition at line 402 of file SkTArray.h.

402 {
403 if (fData == nullptr) {
404 SkASSERT(fSize == 0);
405 }
406 return fData + fSize;
407 }

◆ end() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T * skia_private::TArray< T, MEM_MOVE >::end ( ) const
inline

Definition at line 408 of file SkTArray.h.

408 {
409 if (fData == nullptr) {
410 SkASSERT(fSize == 0);
411 }
412 return fData + fSize;
413 }

◆ fromBack() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::fromBack ( int  i)
inline

equivalent to operator[](size()-1-i)

Definition at line 488 of file SkTArray.h.

488 {
489 return (*this)[fSize - i - 1];
490 }

◆ fromBack() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T & skia_private::TArray< T, MEM_MOVE >::fromBack ( int  i) const
inline

Definition at line 492 of file SkTArray.h.

492 {
493 return (*this)[fSize - i - 1];
494 }

◆ front() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::front ( )
inline

equivalent to operator[](0)

Definition at line 462 of file SkTArray.h.

462 {
464 return fData[0];
465 }

◆ front() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T & skia_private::TArray< T, MEM_MOVE >::front ( ) const
inline

Definition at line 467 of file SkTArray.h.

467 {
469 return fData[0];
470 }

◆ move_back()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::move_back ( TArray< T, MEM_MOVE > &  that)
inline

Moves all elements of that to the end of this array, leaving that empty. This is a no-op if that is empty or equal to this array.

Definition at line 378 of file SkTArray.h.

378 {
379 if (that.empty() || &that == this) {
380 return;
381 }
382 void* dst = this->push_back_raw(that.size());
383 // After move() returns, the contents of `dst` will have either been in-place initialized
384 // using a the move constructor (per-item from `that`'s elements), or will have been
385 // mem-copied into when MEM_MOVE is true (now valid objects).
386 that.move(dst);
387 // All items in `that` have either been destroyed (when MEM_MOVE is false) or should be
388 // considered invalid (when MEM_MOVE is true). Reset fSize to 0 directly to skip any further
389 // per-item destruction.
390 that.changeSize(0);
391 }
dst
Definition cp.py:12

◆ move_back_n()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::move_back_n ( int  n,
T t 
)
inline

Version of above that uses the move constructor to set n items.

Definition at line 302 of file SkTArray.h.

302 {
303 SkASSERT(n >= 0);
304 this->checkRealloc(n, kGrowing);
305 T* end = this->end();
306 this->changeSize(fSize + n);
307 for (int i = 0; i < n; ++i) {
308 new (end + i) T(std::move(t[i]));
309 }
310 return end;
311 }

◆ operator!=()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
bool skia_private::TArray< T, MEM_MOVE >::operator!= ( const TArray< T, MEM_MOVE > &  right) const
inline

Definition at line 509 of file SkTArray.h.

509 {
510 return !(*this == right);
511 }
static bool right(const SkPoint &p0, const SkPoint &p1)

◆ operator=() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
TArray & skia_private::TArray< T, MEM_MOVE >::operator= ( const TArray< T, MEM_MOVE > &  that)
inline

Definition at line 86 of file SkTArray.h.

86 {
87 if (this == &that) {
88 return *this;
89 }
90 this->clear();
91 this->checkRealloc(that.size(), kExactFit);
92 this->changeSize(that.fSize);
93 this->copy(that.fData);
94 return *this;
95 }

◆ operator=() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
TArray & skia_private::TArray< T, MEM_MOVE >::operator= ( TArray< T, MEM_MOVE > &&  that)
inline

Definition at line 97 of file SkTArray.h.

97 {
98 if (this != &that) {
99 this->clear();
100 this->unpoison();
101 that.unpoison();
102 if (that.fOwnMemory) {
103 // The storage is on the heap, so move the data pointer.
104 if (fOwnMemory) {
105 sk_free(fData);
106 }
107
108 fData = std::exchange(that.fData, nullptr);
109
110 // Can't use exchange with bitfields.
111 fCapacity = that.fCapacity;
112 that.fCapacity = 0;
113
114 fOwnMemory = true;
115
116 this->changeSize(that.fSize);
117 } else {
118 // The data is stored inline in that, so move it element-by-element.
119 this->checkRealloc(that.size(), kExactFit);
120 this->changeSize(that.fSize);
121 that.move(fData);
122 }
123 that.changeSize(0);
124 }
125 return *this;
126 }

◆ operator==()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
bool skia_private::TArray< T, MEM_MOVE >::operator== ( const TArray< T, MEM_MOVE > &  right) const
inline

Definition at line 496 of file SkTArray.h.

496 {
497 int leftCount = this->size();
498 if (leftCount != right.size()) {
499 return false;
500 }
501 for (int index = 0; index < leftCount; ++index) {
502 if (fData[index] != right.fData[index]) {
503 return false;
504 }
505 }
506 return true;
507 }

◆ operator[]() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::operator[] ( int  i)
inline

Get the i^th element.

Definition at line 448 of file SkTArray.h.

448 {
449 return fData[sk_collection_check_bounds(i, this->size())];
450 }
SK_API T sk_collection_check_bounds(T i, T size)
Definition SkAssert.h:143

◆ operator[]() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
const T & skia_private::TArray< T, MEM_MOVE >::operator[] ( int  i) const
inline

Definition at line 452 of file SkTArray.h.

452 {
453 return fData[sk_collection_check_bounds(i, this->size())];
454 }

◆ pop_back()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::pop_back ( )
inline

Removes the last element. Not safe to call when size() == 0.

Definition at line 316 of file SkTArray.h.

316 {
318 fData[fSize - 1].~T();
319 this->changeSize(fSize - 1);
320 }

◆ pop_back_n()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::pop_back_n ( int  n)
inline

Removes the last n elements. Not safe to call when size() < n.

Definition at line 325 of file SkTArray.h.

325 {
326 SkASSERT(n >= 0);
327 SkASSERT(this->size() >= n);
328 int i = fSize;
329 while (i-- > fSize - n) {
330 (*this)[i].~T();
331 }
332 this->changeSize(fSize - n);
333 }

◆ push_back() [1/3]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::push_back ( )
inline

Adds one new default-initialized T value and returns it by reference. Note that the reference only remains valid until the next call that adds or removes elements.

Definition at line 200 of file SkTArray.h.

200 {
201 void* newT = this->push_back_raw(1);
202 return *new (newT) T;
203 }

◆ push_back() [2/3]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::push_back ( const T t)
inline

Adds one new T value which is copy-constructed, returning it by reference. As always, the reference only remains valid until the next call that adds or removes elements.

Definition at line 209 of file SkTArray.h.

209 {
210 this->unpoison();
211 T* newT;
212 if (this->capacity() > fSize) SK_LIKELY {
213 // Copy over the element directly.
214 newT = new (fData + fSize) T(t);
215 } else {
216 newT = this->growAndConstructAtEnd(t);
217 }
218
219 this->changeSize(fSize + 1);
220 return *newT;
221 }

◆ push_back() [3/3]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T & skia_private::TArray< T, MEM_MOVE >::push_back ( T &&  t)
inline

Adds one new T value which is copy-constructed, returning it by reference.

Definition at line 226 of file SkTArray.h.

226 {
227 this->unpoison();
228 T* newT;
229 if (this->capacity() > fSize) SK_LIKELY {
230 // Move over the element directly.
231 newT = new (fData + fSize) T(std::move(t));
232 } else {
233 newT = this->growAndConstructAtEnd(std::move(t));
234 }
235
236 this->changeSize(fSize + 1);
237 return *newT;
238 }

◆ push_back_n() [1/3]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::push_back_n ( int  n)
inline

Allocates n more default-initialized T values, and returns the address of the start of that new range. Note: this address is only valid until the next API call made on the array that might add or remove elements.

Definition at line 262 of file SkTArray.h.

262 {
263 SkASSERT(n >= 0);
264 T* newTs = TCast(this->push_back_raw(n));
265 for (int i = 0; i < n; ++i) {
266 new (&newTs[i]) T;
267 }
268 return newTs;
269 }

◆ push_back_n() [2/3]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::push_back_n ( int  n,
const T t 
)
inline

Version of above that uses a copy constructor to initialize all n items to the same T.

Definition at line 275 of file SkTArray.h.

275 {
276 SkASSERT(n >= 0);
277 T* newTs = TCast(this->push_back_raw(n));
278 for (int i = 0; i < n; ++i) {
279 new (&newTs[i]) T(t);
280 }
281 return static_cast<T*>(newTs);
282 }

◆ push_back_n() [3/3]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
T * skia_private::TArray< T, MEM_MOVE >::push_back_n ( int  n,
const T  t[] 
)
inline

Version of above that uses a copy constructor to initialize the n items to separate T values.

Definition at line 288 of file SkTArray.h.

288 {
289 SkASSERT(n >= 0);
290 this->checkRealloc(n, kGrowing);
291 T* end = this->end();
292 this->changeSize(fSize + n);
293 for (int i = 0; i < n; ++i) {
294 new (end + i) T(t[i]);
295 }
296 return end;
297 }

◆ removeShuffle()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::removeShuffle ( int  n)
inline

Definition at line 183 of file SkTArray.h.

183 {
184 SkASSERT(n < this->size());
185 int newCount = fSize - 1;
186 fData[n].~T();
187 if (n != newCount) {
188 this->move(n, newCount);
189 }
190 this->changeSize(newCount);
191 }

◆ reserve()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::reserve ( int  n)
inline

Ensures there is enough reserved space for at least n elements. This is guaranteed at least until the array size grows above n and subsequently shrinks below n, any version of reset() is called, or reserve() is called again.

Definition at line 165 of file SkTArray.h.

165 {
166 SkASSERT(n >= 0);
167 if (n > this->size()) {
168 this->checkRealloc(n - this->size(), kGrowing);
169 }
170 }

◆ reserve_exact()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::reserve_exact ( int  n)
inline

Ensures there is enough reserved space for exactly n elements. The same capacity guarantees as above apply.

Definition at line 176 of file SkTArray.h.

176 {
177 SkASSERT(n >= 0);
178 if (n > this->size()) {
179 this->checkRealloc(n - this->size(), kExactFit);
180 }
181 }

◆ reset() [1/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::reset ( const T array,
int  count 
)
inline

Resets to a copy of a C array and resets any reserve count.

Definition at line 152 of file SkTArray.h.

152 {
153 SkASSERT(count >= 0);
154 this->clear();
155 this->checkRealloc(count, kExactFit);
156 this->changeSize(count);
157 this->copy(array);
158 }

◆ reset() [2/2]

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::reset ( int  n)
inline

Resets to size() = n newly constructed T objects and resets any reserve count.

Definition at line 139 of file SkTArray.h.

139 {
140 SkASSERT(n >= 0);
141 this->clear();
142 this->checkRealloc(n, kExactFit);
143 this->changeSize(n);
144 for (int i = 0; i < this->size(); ++i) {
145 new (fData + i) T;
146 }
147 }

◆ resize()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::resize ( size_t  count)
inline

Definition at line 418 of file SkTArray.h.

418{ this->resize_back((int)count); }
void resize_back(int newCount)
Definition SkTArray.h:338

◆ resize_back()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::resize_back ( int  newCount)
inline

Pushes or pops from the back to resize. Pushes will be default initialized.

Definition at line 338 of file SkTArray.h.

338 {
339 SkASSERT(newCount >= 0);
340 if (newCount > this->size()) {
341 if (this->empty()) {
342 // When the container is completely empty, grow to exactly the requested size.
343 this->checkRealloc(newCount, kExactFit);
344 }
345 this->push_back_n(newCount - fSize);
346 } else if (newCount < this->size()) {
347 this->pop_back_n(fSize - newCount);
348 }
349 }
T * push_back_n(int n)
Definition SkTArray.h:262
void pop_back_n(int n)
Definition SkTArray.h:325

◆ shrink_to_fit()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::shrink_to_fit ( )
inline

Definition at line 425 of file SkTArray.h.

425 {
426 if (!fOwnMemory || fSize == fCapacity) {
427 return;
428 }
429 this->unpoison();
430 if (fSize == 0) {
431 sk_free(fData);
432 fData = nullptr;
433 fCapacity = 0;
434 } else {
435 SkSpan<std::byte> allocation = Allocate(fSize);
436 this->move(TCast(allocation.data()));
437 if (fOwnMemory) {
438 sk_free(fData);
439 }
440 // Poison is applied in `setDataFromBytes`.
441 this->setDataFromBytes(allocation);
442 }
443 }
constexpr T * data() const
Definition SkSpan_impl.h:94

◆ size()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
int skia_private::TArray< T, MEM_MOVE >::size ( ) const
inline

Definition at line 416 of file SkTArray.h.

416{ return fSize; }

◆ size_bytes()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
size_t skia_private::TArray< T, MEM_MOVE >::size_bytes ( ) const
inline

Definition at line 417 of file SkTArray.h.

417{ return Bytes(fSize); }

◆ swap()

template<typename T , bool MEM_MOVE = sk_is_trivially_relocatable_v<T>>
void skia_private::TArray< T, MEM_MOVE >::swap ( TArray< T, MEM_MOVE > &  that)
inline

Swaps the contents of this array with that array. Does a pointer swap if possible, otherwise copies the T values.

Definition at line 353 of file SkTArray.h.

353 {
354 using std::swap;
355 if (this == &that) {
356 return;
357 }
358 if (fOwnMemory && that.fOwnMemory) {
359 swap(fData, that.fData);
360 swap(fSize, that.fSize);
361
362 // Can't use swap because fCapacity is a bit field.
363 auto allocCount = fCapacity;
364 fCapacity = that.fCapacity;
365 that.fCapacity = allocCount;
366 } else {
367 // This could be more optimal...
368 TArray copy(std::move(that));
369 that = std::move(*this);
370 *this = std::move(copy);
371 }
372 }
void swap(TArray &that)
Definition SkTArray.h:353

The documentation for this class was generated from the following file: