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

#include <SkFixedArray.h>

Public Types

using value_type = T
 

Public Member Functions

 FixedArray ()=default
 
 FixedArray (std::initializer_list< T > values)
 
 FixedArray (int reserveCount)
 
 FixedArray (const T *array, int count)
 
 FixedArray (const FixedArray< N, T > &that)
 
FixedArray< N, T > & operator= (const FixedArray< N, T > &that)
 
Toperator[] (size_t index)
 
const Toperator[] (size_t index) const
 
bool operator== (const FixedArray< N, T > &that) const
 
bool operator!= (const FixedArray< N, T > &that) const
 
int size () const
 
bool empty () const
 
void clear ()
 
void reset (const T *array, int count)
 
void resize (int newSize)
 
Tpush_back ()
 
void push_back (T x)
 
void pop_back ()
 
void removeShuffle (int n)
 
Tdata ()
 
const Tdata () const
 
Tbegin ()
 
const Tbegin () const
 
Tend ()
 
const Tend () const
 
Tfront ()
 
const Tfront () const
 
Tback ()
 
const Tback () const
 
void reserve (int size)
 
constexpr int capacity () const
 

Detailed Description

template<int N, typename T>
class skia_private::FixedArray< N, T >

Represents an array of T (must be a trivial type) that cannot grow past a fixed size N. The fixed-size restriction allows for tighter codegen and a smaller memory footprint. Missing methods from TArray (e.g. push_back_n) can be added on demand.

The trivial-type restriction is only to simplify implementation; if there is a need, we can adopt proper move/copy semantics in this class as well.

Definition at line 29 of file SkFixedArray.h.

Member Typedef Documentation

◆ value_type

template<int N, typename T >
using skia_private::FixedArray< N, T >::value_type = T

Definition at line 31 of file SkFixedArray.h.

Constructor & Destructor Documentation

◆ FixedArray() [1/5]

template<int N, typename T >
skia_private::FixedArray< N, T >::FixedArray ( )
default

◆ FixedArray() [2/5]

template<int N, typename T >
skia_private::FixedArray< N, T >::FixedArray ( std::initializer_list< T values)
inline

Definition at line 35 of file SkFixedArray.h.

35 {
36 SkASSERT(values.size() <= N);
37 for (T value : values) {
38 fData[fSize++] = value;
39 }
40 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define N
Definition: beziers.cpp:19
uint8_t value
#define T
Definition: precompiler.cc:65

◆ FixedArray() [3/5]

template<int N, typename T >
skia_private::FixedArray< N, T >::FixedArray ( int  reserveCount)
inline

Definition at line 42 of file SkFixedArray.h.

42 {
43 // This is here to satisfy the TArray interface. Setting a reserve count on a fixed array
44 // isn't useful.
45 SkASSERT(reserveCount >= 0);
46 SkASSERT(reserveCount <= N);
47 }

◆ FixedArray() [4/5]

template<int N, typename T >
skia_private::FixedArray< N, T >::FixedArray ( const T array,
int  count 
)
inline

Definition at line 49 of file SkFixedArray.h.

49 {
50 this->reset(array, count);
51 }
int count
Definition: FontMgrTest.cpp:50
void reset(const T *array, int count)
Definition: SkFixedArray.h:94

◆ FixedArray() [5/5]

template<int N, typename T >
skia_private::FixedArray< N, T >::FixedArray ( const FixedArray< N, T > &  that)
inline

Definition at line 53 of file SkFixedArray.h.

53 {
54 this->reset(that.data(), that.size());
55 }

Member Function Documentation

◆ back() [1/2]

template<int N, typename T >
T & skia_private::FixedArray< N, T >::back ( )
inline

Definition at line 174 of file SkFixedArray.h.

174 {
175 SkASSERT(fSize > 0);
176 return fData[fSize - 1];
177 }

◆ back() [2/2]

template<int N, typename T >
const T & skia_private::FixedArray< N, T >::back ( ) const
inline

Definition at line 179 of file SkFixedArray.h.

179 {
180 SkASSERT(fSize > 0);
181 return fData[fSize - 1];
182 }

◆ begin() [1/2]

template<int N, typename T >
T * skia_private::FixedArray< N, T >::begin ( )
inline

Definition at line 148 of file SkFixedArray.h.

148 {
149 return fData;
150 }

◆ begin() [2/2]

template<int N, typename T >
const T * skia_private::FixedArray< N, T >::begin ( ) const
inline

Definition at line 152 of file SkFixedArray.h.

152 {
153 return fData;
154 }

◆ capacity()

template<int N, typename T >
constexpr int skia_private::FixedArray< N, T >::capacity ( ) const
inlineconstexpr

Definition at line 190 of file SkFixedArray.h.

190 {
191 return N;
192 }

◆ clear()

template<int N, typename T >
void skia_private::FixedArray< N, T >::clear ( )
inline

Definition at line 90 of file SkFixedArray.h.

90 {
91 fSize = 0;
92 }

◆ data() [1/2]

template<int N, typename T >
T * skia_private::FixedArray< N, T >::data ( )
inline

Definition at line 140 of file SkFixedArray.h.

140 {
141 return fData;
142 }

◆ data() [2/2]

template<int N, typename T >
const T * skia_private::FixedArray< N, T >::data ( ) const
inline

Definition at line 144 of file SkFixedArray.h.

144 {
145 return fData;
146 }

◆ empty()

template<int N, typename T >
bool skia_private::FixedArray< N, T >::empty ( ) const
inline

Definition at line 86 of file SkFixedArray.h.

86 {
87 return fSize == 0;
88 }

◆ end() [1/2]

template<int N, typename T >
T * skia_private::FixedArray< N, T >::end ( )
inline

Definition at line 156 of file SkFixedArray.h.

156 {
157 return fData + fSize;
158 }

◆ end() [2/2]

template<int N, typename T >
const T * skia_private::FixedArray< N, T >::end ( ) const
inline

Definition at line 160 of file SkFixedArray.h.

160 {
161 return fData + fSize;
162 }

◆ front() [1/2]

template<int N, typename T >
T & skia_private::FixedArray< N, T >::front ( )
inline

Definition at line 164 of file SkFixedArray.h.

164 {
165 SkASSERT(fSize > 0);
166 return fData[0];
167 }

◆ front() [2/2]

template<int N, typename T >
const T & skia_private::FixedArray< N, T >::front ( ) const
inline

Definition at line 169 of file SkFixedArray.h.

169 {
170 SkASSERT(fSize > 0);
171 return fData[0];
172 }

◆ operator!=()

template<int N, typename T >
bool skia_private::FixedArray< N, T >::operator!= ( const FixedArray< N, T > &  that) const
inline

Definition at line 78 of file SkFixedArray.h.

78 {
79 return !this->operator==(that);
80 }
bool operator==(const FixedArray< N, T > &that) const
Definition: SkFixedArray.h:74

◆ operator=()

template<int N, typename T >
FixedArray< N, T > & skia_private::FixedArray< N, T >::operator= ( const FixedArray< N, T > &  that)
inline

Definition at line 57 of file SkFixedArray.h.

57 {
58 if (this != &that) {
59 this->reset(that.data(), that.size());
60 }
61 return *this;
62 }

◆ operator==()

template<int N, typename T >
bool skia_private::FixedArray< N, T >::operator== ( const FixedArray< N, T > &  that) const
inline

Definition at line 74 of file SkFixedArray.h.

74 {
75 return fSize == that.fSize && (0 == memcmp(fData, that.fData, fSize * sizeof(T)));
76 }

◆ operator[]() [1/2]

template<int N, typename T >
T & skia_private::FixedArray< N, T >::operator[] ( size_t  index)
inline

Definition at line 64 of file SkFixedArray.h.

64 {
65 SkASSERT(index < fSize);
66 return fData[index];
67 }

◆ operator[]() [2/2]

template<int N, typename T >
const T & skia_private::FixedArray< N, T >::operator[] ( size_t  index) const
inline

Definition at line 69 of file SkFixedArray.h.

69 {
70 SkASSERT(index < fSize);
71 return fData[index];
72 }

◆ pop_back()

template<int N, typename T >
void skia_private::FixedArray< N, T >::pop_back ( )
inline

Definition at line 126 of file SkFixedArray.h.

126 {
127 SkASSERT(fSize > 0);
128 --fSize;
129 }

◆ push_back() [1/2]

template<int N, typename T >
T & skia_private::FixedArray< N, T >::push_back ( )
inline

Definition at line 114 of file SkFixedArray.h.

114 {
115 SkASSERT(fSize < N);
116 T& ref = fData[fSize++];
117 ref = T();
118 return ref;
119 }

◆ push_back() [2/2]

template<int N, typename T >
void skia_private::FixedArray< N, T >::push_back ( T  x)
inline

Definition at line 121 of file SkFixedArray.h.

121 {
122 SkASSERT(fSize < N);
123 fData[fSize++] = x;
124 }
double x

◆ removeShuffle()

template<int N, typename T >
void skia_private::FixedArray< N, T >::removeShuffle ( int  n)
inline

Definition at line 131 of file SkFixedArray.h.

131 {
132 SkASSERT(n < fSize);
133 int last = fSize - 1;
134 if (n != last) {
135 fData[n] = fData[last];
136 }
137 fSize = last;
138 }

◆ reserve()

template<int N, typename T >
void skia_private::FixedArray< N, T >::reserve ( int  size)
inline

Definition at line 184 of file SkFixedArray.h.

184 {
185 // This is here to satisfy the TArray interface.
186 SkASSERT(size >= 0);
187 SkASSERT(size <= N);
188 }

◆ reset()

template<int N, typename T >
void skia_private::FixedArray< N, T >::reset ( const T array,
int  count 
)
inline

Definition at line 94 of file SkFixedArray.h.

94 {
95 SkASSERT(count >= 0);
96 SkASSERT(count <= N);
97 fSize = count;
98 std::memcpy(fData, array, count * sizeof(T));
99 }

◆ resize()

template<int N, typename T >
void skia_private::FixedArray< N, T >::resize ( int  newSize)
inline

Definition at line 101 of file SkFixedArray.h.

101 {
102 SkASSERT(newSize >= 0);
103 SkASSERT(newSize <= N);
104
105 if (fSize > newSize) {
106 fSize = newSize;
107 } else {
108 while (fSize < newSize) {
109 fData[fSize++] = T();
110 }
111 }
112 }

◆ size()

template<int N, typename T >
int skia_private::FixedArray< N, T >::size ( ) const
inline

Definition at line 82 of file SkFixedArray.h.

82 {
83 return fSize;
84 }

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