Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::BaseGrowableArray< T, B, Allocator > Class Template Reference

#include <growable_array.h>

Inheritance diagram for dart::BaseGrowableArray< T, B, Allocator >:
B A

Public Member Functions

 BaseGrowableArray (Allocator *allocator)
 
 BaseGrowableArray (intptr_t initial_capacity, Allocator *allocator)
 
 BaseGrowableArray (BaseGrowableArray &&other)
 
 ~BaseGrowableArray ()
 
BaseGrowableArrayoperator= (BaseGrowableArray &&other)
 
intptr_t length () const
 
Tdata () const
 
bool is_empty () const
 
void TruncateTo (intptr_t length)
 
bool Contains (const T &other, bool isEqual(const T &, const T &)=nullptr) const
 
void Add (const T &value)
 
TRemoveLast ()
 
Toperator[] (intptr_t index) const
 
void FillWith (const T &value, intptr_t start, intptr_t length)
 
void EnsureLength (intptr_t new_length, const T &default_value)
 
const TAt (intptr_t index) const
 
TLast () const
 
void AddArray (const BaseGrowableArray< T, B, Allocator > &src)
 
void Clear ()
 
void InsertAt (intptr_t idx, const T &value)
 
void Reverse ()
 
void Swap (intptr_t i, intptr_t j)
 
void RemoveAt (intptr_t i)
 
void EraseAt (intptr_t idx)
 
void SetLength (intptr_t new_length)
 
void Resize (intptr_t new_length)
 
void Sort (int compare(const T *, const T *))
 
void StealBuffer (T **buffer, intptr_t *length)
 
Tbegin ()
 
const Tbegin () const
 
Tend ()
 
const Tend () const
 
- Public Member Functions inherited from B
 B ()
 
void setValues (int v) override
 
bool checkValues (int v) override
 
- Public Member Functions inherited from A
 A ()
 
virtual void setValues (int v)
 
virtual bool checkValues (int v)
 
virtual ~A ()
 
void * operator new (size_t size)
 
void operator delete (void *p)
 

Additional Inherited Members

- Static Public Member Functions inherited from A
static ACreate (SkRandom *r)
 
static void SetAllocator (size_t preallocSize, size_t minAllocSize)
 
static void ResetAllocator ()
 
static void ValidatePool ()
 

Detailed Description

template<typename T, typename B, typename Allocator>
class dart::BaseGrowableArray< T, B, Allocator >

Definition at line 19 of file growable_array.h.

Constructor & Destructor Documentation

◆ BaseGrowableArray() [1/3]

template<typename T , typename B , typename Allocator >
dart::BaseGrowableArray< T, B, Allocator >::BaseGrowableArray ( Allocator allocator)
inlineexplicit

Definition at line 21 of file growable_array.h.

22 : length_(0), capacity_(0), data_(nullptr), allocator_(allocator) {}

◆ BaseGrowableArray() [2/3]

template<typename T , typename B , typename Allocator >
dart::BaseGrowableArray< T, B, Allocator >::BaseGrowableArray ( intptr_t  initial_capacity,
Allocator allocator 
)
inline

Definition at line 24 of file growable_array.h.

25 : length_(0), capacity_(0), data_(nullptr), allocator_(allocator) {
26 if (initial_capacity > 0) {
27 capacity_ = Utils::RoundUpToPowerOfTwo(initial_capacity);
28 data_ = allocator_->template Alloc<T>(capacity_);
29 }
30 }
static constexpr uintptr_t RoundUpToPowerOfTwo(uintptr_t x)
Definition: utils.h:135

◆ BaseGrowableArray() [3/3]

template<typename T , typename B , typename Allocator >
dart::BaseGrowableArray< T, B, Allocator >::BaseGrowableArray ( BaseGrowableArray< T, B, Allocator > &&  other)
inline

Definition at line 32 of file growable_array.h.

33 : length_(other.length_),
34 capacity_(other.capacity_),
35 data_(other.data_),
36 allocator_(other.allocator_) {
37 other.length_ = 0;
38 other.capacity_ = 0;
39 other.data_ = nullptr;
40 }

◆ ~BaseGrowableArray()

template<typename T , typename B , typename Allocator >
dart::BaseGrowableArray< T, B, Allocator >::~BaseGrowableArray ( )
inline

Definition at line 42 of file growable_array.h.

42{ allocator_->template Free<T>(data_, capacity_); }

Member Function Documentation

◆ Add()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::Add ( const T value)
inline

Definition at line 84 of file growable_array.h.

84 {
85 Resize(length() + 1);
86 Last() = value;
87 }
void Resize(intptr_t new_length)
intptr_t length() const
uint8_t value

◆ AddArray()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::AddArray ( const BaseGrowableArray< T, B, Allocator > &  src)
inline

Definition at line 131 of file growable_array.h.

131 {
132 for (intptr_t i = 0; i < src.length(); i++) {
133 Add(src[i]);
134 }
135 }
void Add(const T &value)

◆ At()

template<typename T , typename B , typename Allocator >
const T & dart::BaseGrowableArray< T, B, Allocator >::At ( intptr_t  index) const
inline

Definition at line 124 of file growable_array.h.

124{ return operator[](index); }
T & operator[](intptr_t index) const

◆ begin() [1/2]

template<typename T , typename B , typename Allocator >
T * dart::BaseGrowableArray< T, B, Allocator >::begin ( )
inline

Definition at line 206 of file growable_array.h.

206{ return &data_[0]; }

◆ begin() [2/2]

template<typename T , typename B , typename Allocator >
const T * dart::BaseGrowableArray< T, B, Allocator >::begin ( ) const
inline

Definition at line 207 of file growable_array.h.

207{ return &data_[0]; }

◆ Clear()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::Clear ( )
inline

Definition at line 137 of file growable_array.h.

137{ length_ = 0; }

◆ Contains()

template<typename T , typename B , typename Allocator >
bool dart::BaseGrowableArray< T, B, Allocator >::Contains ( const T other,
bool   isEqualconst T &, const T & = nullptr 
) const
inline

Definition at line 69 of file growable_array.h.

70 {
71 for (const auto& value : *this) {
72 if (value == other) {
73 // Value identity should imply isEqual.
74 ASSERT(isEqual == nullptr || isEqual(value, other));
75 return true;
76 }
77 if (isEqual != nullptr && isEqual(value, other)) {
78 return true;
79 }
80 }
81 return false;
82 }
#define ASSERT(E)

◆ data()

template<typename T , typename B , typename Allocator >
T * dart::BaseGrowableArray< T, B, Allocator >::data ( ) const
inline

Definition at line 61 of file growable_array.h.

61{ return data_; }

◆ end() [1/2]

template<typename T , typename B , typename Allocator >
T * dart::BaseGrowableArray< T, B, Allocator >::end ( )
inline

Definition at line 209 of file growable_array.h.

209{ return &data_[length_]; }

◆ end() [2/2]

template<typename T , typename B , typename Allocator >
const T * dart::BaseGrowableArray< T, B, Allocator >::end ( ) const
inline

Definition at line 210 of file growable_array.h.

210{ return &data_[length_]; }

◆ EnsureLength()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::EnsureLength ( intptr_t  new_length,
const T default_value 
)
inline

Definition at line 114 of file growable_array.h.

114 {
115 const intptr_t old_length = length_;
116 if (old_length < new_length) {
117 Resize(new_length);
118 for (intptr_t i = old_length; i < new_length; ++i) {
119 (*this)[i] = default_value;
120 }
121 }
122 }

◆ EraseAt()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::EraseAt ( intptr_t  idx)
inline

Definition at line 179 of file growable_array.h.

179 {
180 ASSERT(idx >= 0);
181 ASSERT(idx < length_);
182 for (intptr_t i = idx; i < length_ - 1; i++) {
183 data_[i] = data_[i + 1];
184 }
185 RemoveLast();
186 }

◆ FillWith()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::FillWith ( const T value,
intptr_t  start,
intptr_t  length 
)
inline

Definition at line 103 of file growable_array.h.

103 {
104 ASSERT(start >= 0);
105 ASSERT(length >= 0);
106 ASSERT(start <= length_);
107
108 Resize(start + length);
109 for (intptr_t i = 0; i < length; ++i) {
110 data_[start + i] = value;
111 }
112 }

◆ InsertAt()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::InsertAt ( intptr_t  idx,
const T value 
)
inline

Definition at line 139 of file growable_array.h.

139 {
140 Resize(length() + 1);
141 for (intptr_t i = length_ - 2; i >= idx; i--) {
142 data_[i + 1] = data_[i];
143 }
144 data_[idx] = value;
145 }

◆ is_empty()

template<typename T , typename B , typename Allocator >
bool dart::BaseGrowableArray< T, B, Allocator >::is_empty ( ) const
inline

Definition at line 62 of file growable_array.h.

62{ return length_ == 0; }

◆ Last()

template<typename T , typename B , typename Allocator >
T & dart::BaseGrowableArray< T, B, Allocator >::Last ( ) const
inline

Definition at line 126 of file growable_array.h.

126 {
127 ASSERT(length_ > 0);
128 return operator[](length_ - 1);
129 }

◆ length()

template<typename T , typename B , typename Allocator >
intptr_t dart::BaseGrowableArray< T, B, Allocator >::length ( ) const
inline

Definition at line 60 of file growable_array.h.

60{ return length_; }

◆ operator=()

template<typename T , typename B , typename Allocator >
BaseGrowableArray & dart::BaseGrowableArray< T, B, Allocator >::operator= ( BaseGrowableArray< T, B, Allocator > &&  other)
inline

Definition at line 44 of file growable_array.h.

44 {
45 intptr_t temp = other.length_;
46 other.length_ = length_;
47 length_ = temp;
48 temp = other.capacity_;
49 other.capacity_ = capacity_;
50 capacity_ = temp;
51 T* temp_data = other.data_;
52 other.data_ = data_;
53 data_ = temp_data;
54 Allocator* temp_allocator = other.allocator_;
55 other.allocator_ = allocator_;
56 allocator_ = temp_allocator;
57 return *this;
58 }
#define T
Definition: precompiler.cc:65

◆ operator[]()

template<typename T , typename B , typename Allocator >
T & dart::BaseGrowableArray< T, B, Allocator >::operator[] ( intptr_t  index) const
inline

Definition at line 96 of file growable_array.h.

96 {
97 ASSERT(0 <= index);
98 ASSERT(index < length_);
99 ASSERT(length_ <= capacity_);
100 return data_[index];
101 }

◆ RemoveAt()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::RemoveAt ( intptr_t  i)
inline

Definition at line 168 of file growable_array.h.

168 {
169 ASSERT(i >= 0);
170 ASSERT(i < length_);
171 intptr_t last = length_ - 1;
172 if (i < last) {
173 Swap(i, last);
174 }
175 RemoveLast();
176 }
void Swap(intptr_t i, intptr_t j)

◆ RemoveLast()

template<typename T , typename B , typename Allocator >
T & dart::BaseGrowableArray< T, B, Allocator >::RemoveLast ( )
inline

Definition at line 89 of file growable_array.h.

89 {
90 ASSERT(length_ > 0);
91 T& result = operator[](length_ - 1);
92 length_--;
93 return result;
94 }
GAsyncResult * result

◆ Resize()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::Resize ( intptr_t  new_length)

Definition at line 232 of file growable_array.h.

232 {
233 if (new_length > capacity_) {
234 intptr_t new_capacity = Utils::RoundUpToPowerOfTwo(new_length);
235 T* new_data =
236 allocator_->template Realloc<T>(data_, capacity_, new_capacity);
237 ASSERT(new_data != nullptr);
238 data_ = new_data;
239 capacity_ = new_capacity;
240 }
241 length_ = new_length;
242}

◆ Reverse()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::Reverse ( )
inline

Definition at line 147 of file growable_array.h.

147 {
148 for (intptr_t i = 0; i < length_ / 2; i++) {
149 const intptr_t j = length_ - 1 - i;
150 T temp = data_[i];
151 data_[i] = data_[j];
152 data_[j] = temp;
153 }
154 }

◆ SetLength()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::SetLength ( intptr_t  new_length)

Definition at line 245 of file growable_array.h.

245 {
246 if (new_length > capacity_) {
247 T* new_data = allocator_->template Alloc<T>(new_length);
248 ASSERT(new_data != nullptr);
249 data_ = new_data;
250 capacity_ = new_length;
251 }
252 length_ = new_length;
253}

◆ Sort()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::Sort ( int   compareconst T *, const T *)
inline

Definition at line 222 of file growable_array.h.

223 {
224 // Avoid calling qsort with a null array.
225 if (length_ == 0) return;
226
227 typedef int (*CompareFunction)(const void*, const void*);
228 qsort(data_, length_, sizeof(T), reinterpret_cast<CompareFunction>(compare));
229}
CompareFunction
Definition: formats.h:546
int compare(const void *untyped_lhs, const void *untyped_rhs)
Definition: skdiff.h:161

◆ StealBuffer()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::StealBuffer ( T **  buffer,
intptr_t *  length 
)
inline

Definition at line 198 of file growable_array.h.

198 {
199 *buffer = data_;
200 *length = length_;
201 data_ = nullptr;
202 length_ = 0;
203 capacity_ = 0;
204 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ Swap()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::Swap ( intptr_t  i,
intptr_t  j 
)
inline

Definition at line 157 of file growable_array.h.

157 {
158 ASSERT(i >= 0);
159 ASSERT(j >= 0);
160 ASSERT(i < length_);
161 ASSERT(j < length_);
162 T temp = data_[i];
163 data_[i] = data_[j];
164 data_[j] = temp;
165 }

◆ TruncateTo()

template<typename T , typename B , typename Allocator >
void dart::BaseGrowableArray< T, B, Allocator >::TruncateTo ( intptr_t  length)
inline

Definition at line 64 of file growable_array.h.

64 {
65 ASSERT(length_ >= length);
66 length_ = length;
67 }

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