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

#include <SkTArray.h>

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 (SkSpan< const T > data)
 
 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)
 
template<int InitialCapacity>
 TArray (SkSpan< const T > data, 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/10]

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/10]

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:181

◆ TArray() [3/10]

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/10]

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/10]

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: FontMgrTest.cpp:50
Definition: copy.py:1

◆ TArray() [6/10]

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

Creates a TArray by copying contents from an SkSpan. The new array will be heap allocated.

Definition at line 84 of file SkTArray.h.

84: TArray(data.begin(), static_cast<int>(data.size())) {}

◆ TArray() [7/10]

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 89 of file SkTArray.h.

89: 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 133 of file SkTArray.h.

133 {
134 this->destroyAll();
135 this->unpoison();
136 if (fOwnMemory) {
137 sk_free(fData);
138 }
139 }
SK_API void sk_free(void *)

◆ TArray() [8/10]

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 526 of file SkTArray.h.

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

◆ TArray() [9/10]

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 545 of file SkTArray.h.

546 : TArray{storage, size} {
547 this->copy(array);
548 }

◆ TArray() [10/10]

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

Definition at line 550 of file SkTArray.h.

551 : TArray{storage, static_cast<int>(data.size())} {
552 this->copy(data.begin());
553 }
constexpr T * begin() const
Definition: SkSpan_impl.h:90

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 461 of file SkTArray.h.

461{ 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 462 of file SkTArray.h.

462{ 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 480 of file SkTArray.h.

480 {
482 return fData[fSize - 1];
483 }
SK_API void sk_collection_not_empty(bool empty)
Definition: SkAssert.h:175
bool empty() const
Definition: SkTArray.h:199

◆ 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 485 of file SkTArray.h.

485 {
487 return fData[fSize - 1];
488 }

◆ 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 398 of file SkTArray.h.

398 {
399 return fData;
400 }

◆ 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 401 of file SkTArray.h.

401 {
402 return fData;
403 }

◆ 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 518 of file SkTArray.h.

518 {
519 return fCapacity;
520 }

◆ 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 425 of file SkTArray.h.

425 {
426 this->destroyAll();
427 this->changeSize(0);
428 }

◆ 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 419 of file SkTArray.h.

419{ 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 420 of file SkTArray.h.

420{ 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 248 of file SkTArray.h.

248 {
249 this->unpoison();
250 T* newT;
251 if (this->capacity() > fSize) SK_LIKELY {
252 // Emplace the new element in directly.
253 newT = new (fData + fSize) T(std::forward<Args>(args)...);
254 } else {
255 newT = this->growAndConstructAtEnd(std::forward<Args>(args)...);
256 }
257
258 this->changeSize(fSize + 1);
259 return *newT;
260 }
#define SK_LIKELY
Definition: SkAssert.h:27
int capacity() const
Definition: SkTArray.h:518
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define T
Definition: precompiler.cc:65

◆ 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 199 of file SkTArray.h.

199{ 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 407 of file SkTArray.h.

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

◆ 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 413 of file SkTArray.h.

413 {
414 if (fData == nullptr) {
415 SkASSERT(fSize == 0);
416 }
417 return fData + fSize;
418 }

◆ 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 493 of file SkTArray.h.

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

◆ 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 497 of file SkTArray.h.

497 {
498 return (*this)[fSize - i - 1];
499 }

◆ 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 467 of file SkTArray.h.

467 {
469 return fData[0];
470 }

◆ 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 472 of file SkTArray.h.

472 {
474 return fData[0];
475 }

◆ 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 383 of file SkTArray.h.

383 {
384 if (that.empty() || &that == this) {
385 return;
386 }
387 void* dst = this->push_back_raw(that.size());
388 // After move() returns, the contents of `dst` will have either been in-place initialized
389 // using a the move constructor (per-item from `that`'s elements), or will have been
390 // mem-copied into when MEM_MOVE is true (now valid objects).
391 that.move(dst);
392 // All items in `that` have either been destroyed (when MEM_MOVE is false) or should be
393 // considered invalid (when MEM_MOVE is true). Reset fSize to 0 directly to skip any further
394 // per-item destruction.
395 that.changeSize(0);
396 }
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 307 of file SkTArray.h.

307 {
308 SkASSERT(n >= 0);
309 this->checkRealloc(n, kGrowing);
310 T* end = this->end();
311 this->changeSize(fSize + n);
312 for (int i = 0; i < n; ++i) {
313 new (end + i) T(std::move(t[i]));
314 }
315 return end;
316 }

◆ 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 514 of file SkTArray.h.

514 {
515 return !(*this == right);
516 }

◆ 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 91 of file SkTArray.h.

91 {
92 if (this == &that) {
93 return *this;
94 }
95 this->clear();
96 this->checkRealloc(that.size(), kExactFit);
97 this->changeSize(that.fSize);
98 this->copy(that.fData);
99 return *this;
100 }

◆ 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 102 of file SkTArray.h.

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

◆ 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 501 of file SkTArray.h.

501 {
502 int leftCount = this->size();
503 if (leftCount != right.size()) {
504 return false;
505 }
506 for (int index = 0; index < leftCount; ++index) {
507 if (fData[index] != right.fData[index]) {
508 return false;
509 }
510 }
511 return true;
512 }

◆ 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 453 of file SkTArray.h.

453 {
454 return fData[sk_collection_check_bounds(i, this->size())];
455 }
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 457 of file SkTArray.h.

457 {
458 return fData[sk_collection_check_bounds(i, this->size())];
459 }

◆ 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 321 of file SkTArray.h.

321 {
323 fData[fSize - 1].~T();
324 this->changeSize(fSize - 1);
325 }

◆ 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 330 of file SkTArray.h.

330 {
331 SkASSERT(n >= 0);
332 SkASSERT(this->size() >= n);
333 int i = fSize;
334 while (i-- > fSize - n) {
335 (*this)[i].~T();
336 }
337 this->changeSize(fSize - n);
338 }

◆ 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 205 of file SkTArray.h.

205 {
206 void* newT = this->push_back_raw(1);
207 return *new (newT) T;
208 }

◆ 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 214 of file SkTArray.h.

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

◆ 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 231 of file SkTArray.h.

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

◆ 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 267 of file SkTArray.h.

267 {
268 SkASSERT(n >= 0);
269 T* newTs = TCast(this->push_back_raw(n));
270 for (int i = 0; i < n; ++i) {
271 new (&newTs[i]) T;
272 }
273 return newTs;
274 }

◆ 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 280 of file SkTArray.h.

280 {
281 SkASSERT(n >= 0);
282 T* newTs = TCast(this->push_back_raw(n));
283 for (int i = 0; i < n; ++i) {
284 new (&newTs[i]) T(t);
285 }
286 return static_cast<T*>(newTs);
287 }

◆ 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 293 of file SkTArray.h.

293 {
294 SkASSERT(n >= 0);
295 this->checkRealloc(n, kGrowing);
296 T* end = this->end();
297 this->changeSize(fSize + n);
298 for (int i = 0; i < n; ++i) {
299 new (end + i) T(t[i]);
300 }
301 return end;
302 }

◆ 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 188 of file SkTArray.h.

188 {
189 SkASSERT(n < this->size());
190 int newCount = fSize - 1;
191 fData[n].~T();
192 if (n != newCount) {
193 this->move(n, newCount);
194 }
195 this->changeSize(newCount);
196 }

◆ 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 170 of file SkTArray.h.

170 {
171 SkASSERT(n >= 0);
172 if (n > this->size()) {
173 this->checkRealloc(n - this->size(), kGrowing);
174 }
175 }

◆ 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 181 of file SkTArray.h.

181 {
182 SkASSERT(n >= 0);
183 if (n > this->size()) {
184 this->checkRealloc(n - this->size(), kExactFit);
185 }
186 }

◆ 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 157 of file SkTArray.h.

157 {
158 SkASSERT(count >= 0);
159 this->clear();
160 this->checkRealloc(count, kExactFit);
161 this->changeSize(count);
162 this->copy(array);
163 }

◆ 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 144 of file SkTArray.h.

144 {
145 SkASSERT(n >= 0);
146 this->clear();
147 this->checkRealloc(n, kExactFit);
148 this->changeSize(n);
149 for (int i = 0; i < this->size(); ++i) {
150 new (fData + i) T;
151 }
152 }

◆ 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 423 of file SkTArray.h.

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

◆ 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 343 of file SkTArray.h.

343 {
344 SkASSERT(newCount >= 0);
345 if (newCount > this->size()) {
346 if (this->empty()) {
347 // When the container is completely empty, grow to exactly the requested size.
348 this->checkRealloc(newCount, kExactFit);
349 }
350 this->push_back_n(newCount - fSize);
351 } else if (newCount < this->size()) {
352 this->pop_back_n(fSize - newCount);
353 }
354 }
T * push_back_n(int n)
Definition: SkTArray.h:267
void pop_back_n(int n)
Definition: SkTArray.h:330

◆ 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 430 of file SkTArray.h.

430 {
431 if (!fOwnMemory || fSize == fCapacity) {
432 return;
433 }
434 this->unpoison();
435 if (fSize == 0) {
436 sk_free(fData);
437 fData = nullptr;
438 fCapacity = 0;
439 } else {
440 SkSpan<std::byte> allocation = Allocate(fSize);
441 this->move(TCast(allocation.data()));
442 if (fOwnMemory) {
443 sk_free(fData);
444 }
445 // Poison is applied in `setDataFromBytes`.
446 this->setDataFromBytes(allocation);
447 }
448 }
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 421 of file SkTArray.h.

421{ 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 422 of file SkTArray.h.

422{ 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 358 of file SkTArray.h.

358 {
359 using std::swap;
360 if (this == &that) {
361 return;
362 }
363 if (fOwnMemory && that.fOwnMemory) {
364 swap(fData, that.fData);
365 swap(fSize, that.fSize);
366
367 // Can't use swap because fCapacity is a bit field.
368 auto allocCount = fCapacity;
369 fCapacity = that.fCapacity;
370 that.fCapacity = allocCount;
371 } else {
372 // This could be more optimal...
373 TArray copy(std::move(that));
374 that = std::move(*this);
375 *this = std::move(copy);
376 }
377 }
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
void swap(TArray &that)
Definition: SkTArray.h:358

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