MySQL  8.0.22
Source Code Documentation
prealloced_array.h
Go to the documentation of this file.
1 /* Copyright (c) 2013, 2020, Oracle and/or its affiliates.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef PREALLOCED_ARRAY_INCLUDED
24 #define PREALLOCED_ARRAY_INCLUDED
25 
26 /**
27  @file include/prealloced_array.h
28 */
29 
30 #include <stddef.h>
31 #include <algorithm>
32 #include <new>
33 #include <type_traits>
34 #include <utility>
35 
36 #include "my_compiler.h"
37 #include "my_dbug.h"
38 #include "my_inttypes.h"
39 #include "my_sys.h"
40 #include "mysql/psi/psi_memory.h"
42 
43 /**
44  A typesafe replacement for DYNAMIC_ARRAY. We do our own memory management,
45  and pre-allocate space for a number of elements. The purpose is to
46  pre-allocate enough elements to cover normal use cases, thus saving
47  malloc()/free() overhead.
48  If we run out of space, we use malloc to allocate more space.
49 
50  The interface is chosen to be similar to std::vector.
51  We keep the std::vector property that storage is contiguous.
52 
53  @remark
54  Unlike DYNAMIC_ARRAY, elements are properly copied
55  (rather than memcpy()d) if the underlying array needs to be expanded.
56 
57  @remark
58  Depending on Has_trivial_destructor, we destroy objects which are
59  removed from the array (including when the array object itself is destroyed).
60 
61  @tparam Element_type The type of the elements of the container.
62  Elements must be copyable or movable.
63  @tparam Prealloc Number of elements to pre-allocate.
64  */
65 template <typename Element_type, size_t Prealloc>
67  /**
68  Is Element_type trivially destructible? If it is, we don't destroy
69  elements when they are removed from the array or when the array is
70  destroyed.
71  */
72  static constexpr bool Has_trivial_destructor =
74 
75  /**
76  Casts the raw buffer to the proper Element_type.
77  We use a raw buffer rather than Element_type[] in order to avoid having
78  CTORs/DTORs invoked by the C++ runtime.
79  */
80  Element_type *cast_rawbuff() {
81  return static_cast<Element_type *>(static_cast<void *>(m_buff));
82  }
83 
84  public:
85  /// Initial capacity of the array.
86  static const size_t initial_capacity = Prealloc;
87 
88  /// Standard typedefs.
89  typedef Element_type value_type;
90  typedef size_t size_type;
91  typedef ptrdiff_t difference_type;
92 
93  typedef Element_type *iterator;
94  typedef const Element_type *const_iterator;
95 
96  explicit Prealloced_array(PSI_memory_key psi_key)
97  : m_size(0),
98  m_capacity(Prealloc),
100  m_psi_key(psi_key) {
101  static_assert(Prealloc != 0, "We do not want a zero-size array.");
102  }
103 
104  /**
105  Initializes (parts of) the array with default values.
106  Using 'Prealloc' for initial_size makes this similar to a raw C array.
107  */
108  Prealloced_array(PSI_memory_key psi_key, size_t initial_size)
109  : m_size(0),
110  m_capacity(Prealloc),
112  m_psi_key(psi_key) {
113  static_assert(Prealloc != 0, "We do not want a zero-size array.");
114 
115  if (initial_size > Prealloc) {
116  // We avoid using reserve() since it requires Element_type to be copyable.
117  void *mem =
118  my_malloc(m_psi_key, initial_size * element_size(), MYF(MY_WME));
119  if (!mem) return;
120  m_array_ptr = static_cast<Element_type *>(mem);
121  m_capacity = initial_size;
122  }
123  for (size_t ix = 0; ix < initial_size; ++ix) {
124  Element_type *p = &m_array_ptr[m_size++];
125  ::new (p) Element_type();
126  }
127  }
128 
129  /**
130  An object instance "owns" its array, so we do deep copy here.
131  */
133  : m_size(0),
134  m_capacity(Prealloc),
136  m_psi_key(that.m_psi_key) {
137  if (this->reserve(that.capacity())) return;
138  for (const Element_type *p = that.begin(); p != that.end(); ++p)
139  this->push_back(*p);
140  }
141 
143  : m_size(0),
144  m_capacity(Prealloc),
146  m_psi_key(that.m_psi_key) {
147  *this = std::move(that);
148  }
149 
150  /**
151  Range constructor.
152 
153  Constructs a container with as many elements as the range [first,last),
154  with each element constructed from its corresponding element in that range,
155  in the same order.
156  */
157  Prealloced_array(PSI_memory_key psi_key, const_iterator first,
158  const_iterator last)
159  : m_size(0),
160  m_capacity(Prealloc),
162  m_psi_key(psi_key) {
163  if (this->reserve(last - first)) return;
164  for (; first != last; ++first) push_back(*first);
165  }
166 
167  Prealloced_array(std::initializer_list<Element_type> elems)
168  : Prealloced_array(PSI_NOT_INSTRUMENTED, elems.begin(), elems.end()) {}
169 
170  /**
171  Copies all the elements from 'that' into this container.
172  Any objects in this container are destroyed first.
173  */
175  this->clear();
176  if (this->reserve(that.capacity())) return *this;
177  for (const Element_type *p = that.begin(); p != that.end(); ++p)
178  this->push_back(*p);
179  return *this;
180  }
181 
183  this->clear();
184  if (that.m_array_ptr != that.cast_rawbuff()) {
186  // The array is on the heap, so we can just grab it.
187  m_array_ptr = that.m_array_ptr;
188  m_capacity = that.m_capacity;
189  m_size = that.m_size;
190  that.m_size = 0;
191  that.m_array_ptr = that.cast_rawbuff();
192  that.m_capacity = Prealloc;
193  } else {
194  // Move over each element.
195  if (this->reserve(that.capacity())) return *this;
196  for (Element_type *p = that.begin(); p != that.end(); ++p)
197  this->push_back(std::move(*p));
198  that.clear();
199  }
200  return *this;
201  }
202 
203  /**
204  Runs DTOR on all elements if needed.
205  Deallocates array if we exceeded the Preallocated amount.
206  */
208  if (!Has_trivial_destructor) {
209  clear();
210  }
212  }
213 
214  size_t capacity() const { return m_capacity; }
215  size_t element_size() const { return sizeof(Element_type); }
216  bool empty() const { return m_size == 0; }
217  size_t size() const { return m_size; }
218 
219  Element_type &at(size_t n) {
220  DBUG_ASSERT(n < size());
221  return m_array_ptr[n];
222  }
223 
224  const Element_type &at(size_t n) const {
225  DBUG_ASSERT(n < size());
226  return m_array_ptr[n];
227  }
228 
229  Element_type &operator[](size_t n) { return at(n); }
230  const Element_type &operator[](size_t n) const { return at(n); }
231 
232  Element_type &back() { return at(size() - 1); }
233  const Element_type &back() const { return at(size() - 1); }
234 
235  Element_type &front() { return at(0); }
236  const Element_type &front() const { return at(0); }
237 
238  /**
239  begin : Returns a pointer to the first element in the array.
240  end : Returns a pointer to the past-the-end element in the array.
241  */
242  iterator begin() { return m_array_ptr; }
243  iterator end() { return m_array_ptr + size(); }
244  const_iterator begin() const { return m_array_ptr; }
245  const_iterator end() const { return m_array_ptr + size(); }
246  /// Returns a constant pointer to the first element in the array.
247  const_iterator cbegin() const { return begin(); }
248  /// Returns a constant pointer to the past-the-end element in the array.
249  const_iterator cend() const { return end(); }
250 
251  /**
252  Assigns a value to an arbitrary element, even where n >= size().
253  The array is extended with default values if necessary.
254  @retval true if out-of-memory, false otherwise.
255  */
256  bool assign_at(size_t n, const value_type &val) {
257  if (n < size()) {
258  at(n) = val;
259  return false;
260  }
261  if (reserve(n + 1)) return true;
262  resize(n);
263  return push_back(val);
264  }
265 
266  /**
267  Reserves space for array elements.
268  Copies (or moves, if possible) over existing elements, in case we
269  are re-expanding the array.
270 
271  @param n number of elements.
272  @retval true if out-of-memory, false otherwise.
273  */
274  bool reserve(size_t n) {
275  if (n <= m_capacity) return false;
276 
277  void *mem = my_malloc(m_psi_key, n * element_size(), MYF(MY_WME));
278  if (!mem) return true;
279  Element_type *new_array = static_cast<Element_type *>(mem);
280 
281  // Move all the existing elements into the new array.
282  for (size_t ix = 0; ix < m_size; ++ix) {
283  Element_type *new_p = &new_array[ix];
284  Element_type &old_p = m_array_ptr[ix];
285  ::new (new_p) Element_type(std::move(old_p)); // Move into new location.
286  if (!Has_trivial_destructor)
287  old_p.~Element_type(); // Destroy the old element.
288  }
289 
291 
292  // Forget the old array;
293  m_array_ptr = new_array;
294  m_capacity = n;
295  return false;
296  }
297 
298  /**
299  Copies an element into the back of the array.
300  Complexity: Constant (amortized time, reallocation may happen).
301  @return true if out-of-memory, false otherwise
302  */
303  bool push_back(const Element_type &element) { return emplace_back(element); }
304 
305  /**
306  Copies (or moves, if possible) an element into the back of the array.
307  Complexity: Constant (amortized time, reallocation may happen).
308  @return true if out-of-memory, false otherwise
309  */
310  bool push_back(Element_type &&element) {
311  return emplace_back(std::move(element));
312  }
313 
314  /**
315  Constructs an element at the back of the array.
316  Complexity: Constant (amortized time, reallocation may happen).
317  @return true if out-of-memory, false otherwise
318  */
319  template <typename... Args>
320  bool emplace_back(Args &&... args) {
321  const size_t expansion_factor = 2;
322  if (m_size == m_capacity && reserve(m_capacity * expansion_factor))
323  return true;
324  Element_type *p = &m_array_ptr[m_size++];
325  ::new (p) Element_type(std::forward<Args>(args)...);
326  return false;
327  }
328 
329  /**
330  Removes the last element in the array, effectively reducing the
331  container size by one. This destroys the removed element.
332  */
333  void pop_back() {
334  DBUG_ASSERT(!empty());
335  if (!Has_trivial_destructor) back().~Element_type();
336  m_size -= 1;
337  }
338 
339  /**
340  The array is extended by inserting a new element before the element at the
341  specified position.
342 
343  This is generally an inefficient operation, since we need to copy
344  elements to make a new "hole" in the array.
345 
346  We use std::rotate to move objects, hence Element_type must be
347  move-assignable and move-constructible.
348 
349  @return an iterator pointing to the inserted value
350  */
351  iterator insert(const_iterator position, const value_type &val) {
352  return emplace(position, val);
353  }
354 
355  /**
356  The array is extended by inserting a new element before the element at the
357  specified position. The element is moved into the array, if possible.
358 
359  This is generally an inefficient operation, since we need to copy
360  elements to make a new "hole" in the array.
361 
362  We use std::rotate to move objects, hence Element_type must be
363  move-assignable and move-constructible.
364 
365  @return an iterator pointing to the inserted value
366  */
367  iterator insert(const_iterator position, value_type &&val) {
368  return emplace(position, std::move(val));
369  }
370 
371  /**
372  The array is extended by inserting a new element before the element at the
373  specified position. The element is constructed in-place.
374 
375  This is generally an inefficient operation, since we need to copy
376  elements to make a new "hole" in the array.
377 
378  We use std::rotate to move objects, hence Element_type must be
379  move-assignable and move-constructible.
380 
381  @return an iterator pointing to the inserted value
382  */
383  template <typename... Args>
384  iterator emplace(const_iterator position, Args &&... args) {
385  const difference_type n = position - begin();
386  emplace_back(std::forward<Args>(args)...);
387  std::rotate(begin() + n, end() - 1, end());
388  return begin() + n;
389  }
390 
391  /**
392  Similar to std::set<>::insert()
393  Extends the array by inserting a new element, but only if it cannot be found
394  in the array already.
395 
396  Assumes that the array is sorted with std::less<Element_type>
397  Insertion using this function will maintain order.
398 
399  @retval A pair, with its member pair::first set an iterator pointing to
400  either the newly inserted element, or to the equivalent element
401  already in the array. The pair::second element is set to true if
402  the new element was inserted, or false if an equivalent element
403  already existed.
404  */
405  std::pair<iterator, bool> insert_unique(const value_type &val) {
406  std::pair<iterator, iterator> p = std::equal_range(begin(), end(), val);
407  // p.first == p.second means we did not find it.
408  if (p.first == p.second) return std::make_pair(insert(p.first, val), true);
409  return std::make_pair(p.first, false);
410  }
411 
412  /**
413  Similar to std::set<>::erase()
414  Removes a single element from the array by value.
415  The removed element is destroyed.
416  This effectively reduces the container size by one.
417 
418  This is generally an inefficient operation, since we need to copy
419  elements to fill the "hole" in the array.
420 
421  Assumes that the array is sorted with std::less<Element_type>.
422 
423  @retval number of elements removed, 0 or 1.
424  */
425  size_type erase_unique(const value_type &val) {
426  std::pair<iterator, iterator> p = std::equal_range(begin(), end(), val);
427  if (p.first == p.second) return 0; // Not found
428  erase(p.first);
429  return 1;
430  }
431 
432  /**
433  Similar to std::set<>::count()
434 
435  @note Assumes that array is maintained with insert_unique/erase_unique.
436 
437  @retval 1 if element is found, 0 otherwise.
438  */
439  size_type count_unique(const value_type &val) const {
440  return std::binary_search(begin(), end(), val);
441  }
442 
443  /**
444  Removes a single element from the array.
445  The removed element is destroyed.
446  This effectively reduces the container size by one.
447 
448  This is generally an inefficient operation, since we need to move
449  or copy elements to fill the "hole" in the array.
450 
451  We use std::move to move objects, hence Element_type must be
452  move-assignable.
453  */
454  iterator erase(const_iterator position) {
455  DBUG_ASSERT(position != end());
456  return erase(position - begin());
457  }
458 
459  /**
460  Removes a single element from the array.
461  */
462  iterator erase(size_t ix) {
463  DBUG_ASSERT(ix < size());
464  iterator pos = begin() + ix;
465  if (pos + 1 != end()) std::move(pos + 1, end(), pos);
466  pop_back();
467  return pos;
468  }
469 
470  /**
471  Removes tail elements from the array.
472  The removed elements are destroyed.
473  This effectively reduces the containers size by 'end() - first'.
474  */
475  void erase_at_end(const_iterator first) {
476  const_iterator last = cend();
477  const difference_type diff = last - first;
478  if (!Has_trivial_destructor) {
479  for (; first != last; ++first) first->~Element_type();
480  }
481  m_size -= diff;
482  }
483 
484  /**
485  Removes a range of elements from the array.
486  The removed elements are destroyed.
487  This effectively reduces the containers size by 'last - first'.
488 
489  This is generally an inefficient operation, since we need to move
490  or copy elements to fill the "hole" in the array.
491 
492  We use std::move to move objects, hence Element_type must be
493  move-assignable.
494  */
495  iterator erase(const_iterator first, const_iterator last) {
496  /*
497  std::move() wants non-const input iterators, otherwise it cannot move and
498  must always copy the elements. Convert first and last from const_iterator
499  to iterator.
500  */
501  iterator start = begin() + (first - cbegin());
502  iterator stop = begin() + (last - cbegin());
503  if (first != last) erase_at_end(std::move(stop, end(), start));
504  return start;
505  }
506 
507  /**
508  Exchanges the content of the container by the content of rhs, which
509  is another vector object of the same type. Sizes may differ.
510 
511  We use std::swap to do the operation.
512  */
513  void swap(Prealloced_array &rhs) {
514  // Just swap pointers if both arrays have done malloc.
515  if (m_array_ptr != cast_rawbuff() &&
516  rhs.m_array_ptr != rhs.cast_rawbuff()) {
517  std::swap(m_size, rhs.m_size);
521  return;
522  }
523  std::swap(*this, rhs);
524  }
525 
526  /**
527  Requests the container to reduce its capacity to fit its size.
528  */
529  void shrink_to_fit() {
530  // Cannot shrink the pre-allocated array.
531  if (m_array_ptr == cast_rawbuff()) return;
532  // No point in swapping.
533  if (size() == capacity()) return;
534  Prealloced_array tmp(m_psi_key, begin(), end());
535  if (size() <= Prealloc) {
536  /*
537  The elements fit in the pre-allocated array. Destruct the
538  heap-allocated array in this, and copy the elements into the
539  pre-allocated array.
540  */
541  this->~Prealloced_array();
542  new (this) Prealloced_array(tmp.m_psi_key, tmp.begin(), tmp.end());
543  } else {
544  // Both this and tmp have a heap-allocated array. Swap pointers.
545  swap(tmp);
546  }
547  }
548 
549  /**
550  Resizes the container so that it contains n elements.
551 
552  If n is smaller than the current container size, the content is
553  reduced to its first n elements, removing those beyond (and
554  destroying them).
555 
556  If n is greater than the current container size, the content is
557  expanded by inserting at the end as many elements as needed to
558  reach a size of n. If val is specified, the new elements are
559  initialized as copies of val, otherwise, they are
560  value-initialized.
561 
562  If n is also greater than the current container capacity, an automatic
563  reallocation of the allocated storage space takes place.
564 
565  Notice that this function changes the actual content of the
566  container by inserting or erasing elements from it.
567  */
568  void resize(size_t n, const Element_type &val = Element_type()) {
569  if (n == m_size) return;
570  if (n > m_size) {
571  if (!reserve(n)) {
572  while (n != m_size) push_back(val);
573  }
574  return;
575  }
576  if (!Has_trivial_destructor) {
577  while (n != m_size) pop_back();
578  }
579  m_size = n;
580  }
581 
582  /**
583  Removes (and destroys) all elements.
584  Does not change capacity.
585  */
586  void clear() {
587  if (!Has_trivial_destructor) {
588  for (Element_type *p = begin(); p != end(); ++p)
589  p->~Element_type(); // Destroy discarded element.
590  }
591  m_size = 0;
592  }
593 
594  private:
595  size_t m_size;
596  size_t m_capacity;
597  // This buffer must be properly aligned.
598  alignas(Element_type) char m_buff[Prealloc * sizeof(Element_type)];
599  Element_type *m_array_ptr;
601 };
602 
603 #endif // PREALLOCED_ARRAY_INCLUDED
size_t capacity() const
Definition: prealloced_array.h:214
const Element_type & operator[](size_t n) const
Definition: prealloced_array.h:230
void resize(size_t n, const Element_type &val=Element_type())
Resizes the container so that it contains n elements.
Definition: prealloced_array.h:568
Element_type * m_array_ptr
Definition: prealloced_array.h:599
iterator erase(size_t ix)
Removes a single element from the array.
Definition: prealloced_array.h:462
#define MY_WME
Definition: my_sys.h:117
Some integer typedefs for easier portability.
Element_type & at(size_t n)
Definition: prealloced_array.h:219
std::pair< iterator, bool > insert_unique(const value_type &val)
Similar to std::set<>::insert() Extends the array by inserting a new element, but only if it cannot b...
Definition: prealloced_array.h:405
Prealloced_array & operator=(const Prealloced_array &that)
Copies all the elements from &#39;that&#39; into this container.
Definition: prealloced_array.h:174
void erase_at_end(const_iterator first)
Removes tail elements from the array.
Definition: prealloced_array.h:475
Prealloced_array(PSI_memory_key psi_key, const_iterator first, const_iterator last)
Range constructor.
Definition: prealloced_array.h:157
Element_type & front()
Definition: prealloced_array.h:235
bool empty() const
Definition: prealloced_array.h:216
const Element_type & back() const
Definition: prealloced_array.h:233
void shrink_to_fit()
Requests the container to reduce its capacity to fit its size.
Definition: prealloced_array.h:529
iterator emplace(const_iterator position, Args &&... args)
The array is extended by inserting a new element before the element at the specified position...
Definition: prealloced_array.h:384
const_iterator begin() const
Definition: prealloced_array.h:244
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:39
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
const_iterator end() const
Definition: prealloced_array.h:245
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:46
size_type erase_unique(const value_type &val)
Similar to std::set<>::erase() Removes a single element from the array by value.
Definition: prealloced_array.h:425
static const size_t initial_capacity
Initial capacity of the array.
Definition: prealloced_array.h:86
static MEM_ROOT mem
Definition: sql_servers.cc:98
Prealloced_array(const Prealloced_array &that)
An object instance "owns" its array, so we do deep copy here.
Definition: prealloced_array.h:132
ptrdiff_t difference_type
Definition: prealloced_array.h:91
Prealloced_array(Prealloced_array &&that)
Definition: prealloced_array.h:142
iterator begin()
begin : Returns a pointer to the first element in the array.
Definition: prealloced_array.h:242
static Bigint * diff(Bigint *a, Bigint *b, Stack_alloc *alloc)
Definition: dtoa.cc:1089
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:66
const Element_type & front() const
Definition: prealloced_array.h:236
#define DBUG_ASSERT(A)
Definition: my_dbug.h:199
size_t size() const
Definition: prealloced_array.h:217
bool emplace_back(Args &&... args)
Constructs an element at the back of the array.
Definition: prealloced_array.h:320
bool assign_at(size_t n, const value_type &val)
Assigns a value to an arbitrary element, even where n >= size().
Definition: prealloced_array.h:256
char * pos
Definition: do_ctype.cc:76
#define MYF(v)
Element_type & back()
Definition: prealloced_array.h:232
Prealloced_array & operator=(Prealloced_array &&that)
Definition: prealloced_array.h:182
const Element_type * const_iterator
Definition: prealloced_array.h:94
iterator insert(const_iterator position, value_type &&val)
The array is extended by inserting a new element before the element at the specified position...
Definition: prealloced_array.h:367
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:161
Element_type * cast_rawbuff()
Casts the raw buffer to the proper Element_type.
Definition: prealloced_array.h:80
const_iterator cend() const
Returns a constant pointer to the past-the-end element in the array.
Definition: prealloced_array.h:249
Prealloced_array(PSI_memory_key psi_key)
Definition: prealloced_array.h:96
Header for compiler-dependent features.
char m_buff[Prealloc *sizeof(Element_type)]
Definition: prealloced_array.h:598
void pop_back()
Removes the last element in the array, effectively reducing the container size by one...
Definition: prealloced_array.h:333
iterator end()
Definition: prealloced_array.h:243
size_t size_type
Definition: prealloced_array.h:90
Common header for many mysys elements.
const Element_type & at(size_t n) const
Definition: prealloced_array.h:224
iterator erase(const_iterator first, const_iterator last)
Removes a range of elements from the array.
Definition: prealloced_array.h:495
bool push_back(Element_type &&element)
Copies (or moves, if possible) an element into the back of the array.
Definition: prealloced_array.h:310
PSI_memory_key m_psi_key
Definition: prealloced_array.h:600
~Prealloced_array()
Runs DTOR on all elements if needed.
Definition: prealloced_array.h:207
static void stop(mysql_harness::PluginFuncEnv *)
Definition: rest_mock_server.cc:276
Performance schema instrumentation interface.
size_type count_unique(const value_type &val) const
Similar to std::set<>::count()
Definition: prealloced_array.h:439
void clear()
Removes (and destroys) all elements.
Definition: prealloced_array.h:586
Prealloced_array(PSI_memory_key psi_key, size_t initial_size)
Initializes (parts of) the array with default values.
Definition: prealloced_array.h:108
size_t m_capacity
Definition: prealloced_array.h:596
int n
Definition: xcom_base.cc:442
Element_type & operator[](size_t n)
Definition: prealloced_array.h:229
size_t element_size() const
Definition: prealloced_array.h:215
const_iterator cbegin() const
Returns a constant pointer to the first element in the array.
Definition: prealloced_array.h:247
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:606
iterator insert(const_iterator position, const value_type &val)
The array is extended by inserting a new element before the element at the specified position...
Definition: prealloced_array.h:351
iterator erase(const_iterator position)
Removes a single element from the array.
Definition: prealloced_array.h:454
const char * p
Definition: ctype-mb.cc:1235
const string value("\alue\)
bool push_back(const Element_type &element)
Copies an element into the back of the array.
Definition: prealloced_array.h:303
Element_type value_type
Standard typedefs.
Definition: prealloced_array.h:89
void * my_malloc(PSI_memory_key key, size_t size, int flags)
Below functions are used by the components.
Definition: my_memory.cc:57
Element_type * iterator
Definition: prealloced_array.h:93
static constexpr bool Has_trivial_destructor
Is Element_type trivially destructible? If it is, we don&#39;t destroy elements when they are removed fro...
Definition: prealloced_array.h:72
bool reserve(size_t n)
Reserves space for array elements.
Definition: prealloced_array.h:274
size_t m_size
Definition: prealloced_array.h:595
void swap(Prealloced_array &rhs)
Exchanges the content of the container by the content of rhs, which is another vector object of the s...
Definition: prealloced_array.h:513
Prealloced_array(std::initializer_list< Element_type > elems)
Definition: prealloced_array.h:167