24#ifndef PREALLOCED_ARRAY_INCLUDED 
   25#define PREALLOCED_ARRAY_INCLUDED 
   70template <
typename Element_type, 
size_t Prealloc>
 
   78      std::is_trivially_destructible<Element_type>::value;
 
  120    static_assert(Prealloc != 0, 
"We do not want a zero-size array.");
 
  129    static_assert(Prealloc != 0, 
"We do not want a zero-size array.");
 
  131    if (initial_size > Prealloc) {
 
  143    for (
size_t ix = 0; ix < initial_size; ++ix) {
 
  144      Element_type *
p = &
buffer()[ix];
 
  145      ::new (
p) Element_type();
 
  154    for (
const Element_type *
p = that.
begin(); 
p != that.
end(); ++
p)
 
  159    *
this = std::move(that);
 
  172    if (this->
reserve(last - first)) 
return;
 
  186    for (
const Element_type *
p = that.
begin(); 
p != that.
end(); ++
p)
 
  193    if (!that.using_inline_buffer()) {
 
  200      that.m_inline_size = 0;
 
  203      if (this->
reserve(that.capacity())) 
return *
this;
 
  204      for (Element_type *
p = that.begin(); 
p != that.end(); ++
p)
 
  231  Element_type &
at(
size_t n) {
 
  236  const Element_type &
at(
size_t n)
 const {
 
  248  const Element_type &
front()
 const { 
return at(0); }
 
  290    if (!
mem) 
return true;
 
  291    Element_type *new_array = 
static_cast<Element_type *
>(
mem);
 
  294    size_t old_size = 
size();
 
  295    for (
size_t ix = 0; ix < old_size; ++ix) {
 
  296      Element_type *new_p = &new_array[ix];
 
  297      Element_type &old_p = 
buffer()[ix];
 
  298      ::new (new_p) Element_type(std::move(old_p));  
 
  300        old_p.~Element_type();  
 
  343  template <
typename... Args>
 
  345    const size_t expansion_factor = 2;
 
  350    ::new (
p) Element_type(std::forward<Args>(args)...);
 
  393    return emplace(position, std::move(val));
 
  408  template <
typename... Args>
 
  431    std::pair<iterator, iterator> 
p = std::equal_range(
begin(), 
end(), val);
 
  433    if (
p.first == 
p.second) 
return std::make_pair(
insert(
p.first, val), 
true);
 
  434    return std::make_pair(
p.first, 
false);
 
  451    std::pair<iterator, iterator> 
p = std::equal_range(
begin(), 
end(), val);
 
  452    if (
p.first == 
p.second) 
return 0;  
 
  465    return std::binary_search(
begin(), 
end(), val);
 
  480    assert(position != 
end());
 
  490    if (pos + 1 != 
end()) std::move(pos + 1, 
end(), pos);
 
  504      for (; first != 
last; ++first) first->~Element_type();
 
  559    if (
size() <= Prealloc) {
 
  592  void resize(
size_t n, 
const Element_type &val = Element_type()) {
 
  593    if (
n == 
size()) 
return;
 
  642              "Check for no unexpected padding");
 
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
 
bool push_back(const Element_type &element)
Copies an element into the back of the array.
Definition: prealloced_array.h:327
 
const Element_type & operator[](size_t n) const
Definition: prealloced_array.h:242
 
iterator erase(const_iterator first, const_iterator last)
Removes a range of elements from the array.
Definition: prealloced_array.h:520
 
Prealloced_array & operator=(const Prealloced_array &that)
Copies all the elements from 'that' into this container.
Definition: prealloced_array.h:183
 
size_type count_unique(const value_type &val) const
Similar to std::set<>::count()
Definition: prealloced_array.h:464
 
Prealloced_array(PSI_memory_key psi_key, const_iterator first, const_iterator last)
Range constructor.
Definition: prealloced_array.h:169
 
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:450
 
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:409
 
bool empty() const
Definition: prealloced_array.h:226
 
Prealloced_array(std::initializer_list< Element_type > elems)
Definition: prealloced_array.h:176
 
const Element_type & front() const
Definition: prealloced_array.h:248
 
Prealloced_array(PSI_memory_key psi_key)
Definition: prealloced_array.h:119
 
Element_type value_type
Standard typedefs.
Definition: prealloced_array.h:112
 
Prealloced_array(const Prealloced_array &that)
An object instance "owns" its array, so we do deep copy here.
Definition: prealloced_array.h:152
 
bool using_inline_buffer() const
Definition: prealloced_array.h:80
 
iterator erase(size_t ix)
Removes a single element from the array.
Definition: prealloced_array.h:487
 
void clear()
Removes (and destroys) all elements.
Definition: prealloced_array.h:610
 
bool reserve(size_t n)
Reserves space for array elements.
Definition: prealloced_array.h:286
 
static constexpr bool Has_trivial_destructor
Is Element_type trivially destructible? If it is, we don't destroy elements when they are removed fro...
Definition: prealloced_array.h:77
 
Element_type & at(size_t n)
Definition: prealloced_array.h:231
 
Prealloced_array(Prealloced_array &&that)
Definition: prealloced_array.h:158
 
const Element_type & at(size_t n) const
Definition: prealloced_array.h:236
 
void resize(size_t n, const Element_type &val=Element_type())
Resizes the container so that it contains n elements.
Definition: prealloced_array.h:592
 
bool emplace_back(Args &&...args)
Constructs an element at the back of the array.
Definition: prealloced_array.h:344
 
const_iterator cbegin() const
Returns a constant pointer to the first element in the array.
Definition: prealloced_array.h:259
 
static const size_t initial_capacity
Initial capacity of the array.
Definition: prealloced_array.h:109
 
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:538
 
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:392
 
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:268
 
void pop_back()
Removes the last element in the array, effectively reducing the container size by one.
Definition: prealloced_array.h:358
 
~Prealloced_array()
Runs DTOR on all elements if needed.
Definition: prealloced_array.h:215
 
void set_size(size_t n)
Definition: prealloced_array.h:92
 
PSI_memory_key m_psi_key
Definition: prealloced_array.h:619
 
Element_type * buffer()
Gets the buffer in use.
Definition: prealloced_array.h:85
 
const Element_type & back() const
Definition: prealloced_array.h:245
 
Element_type * iterator
Definition: prealloced_array.h:116
 
iterator erase(const_iterator position)
Removes a single element from the array.
Definition: prealloced_array.h:479
 
Element_type & operator[](size_t n)
Definition: prealloced_array.h:241
 
size_t capacity() const
Definition: prealloced_array.h:222
 
const Element_type * buffer() const
Definition: prealloced_array.h:88
 
const_iterator cend() const
Returns a constant pointer to the past-the-end element in the array.
Definition: prealloced_array.h:261
 
void shrink_to_fit()
Requests the container to reduce its capacity to fit its size.
Definition: prealloced_array.h:553
 
size_t size() const
Definition: prealloced_array.h:227
 
ptrdiff_t difference_type
Definition: prealloced_array.h:114
 
void erase_at_end(const_iterator first)
Removes tail elements from the array.
Definition: prealloced_array.h:500
 
Prealloced_array & operator=(Prealloced_array &&that)
Definition: prealloced_array.h:191
 
bool push_back(Element_type &&element)
Copies (or moves, if possible) an element into the back of the array.
Definition: prealloced_array.h:334
 
const_iterator begin() const
Definition: prealloced_array.h:256
 
Prealloced_array(PSI_memory_key psi_key, size_t initial_size)
Initializes (parts of) the array with default values.
Definition: prealloced_array.h:127
 
iterator begin()
begin : Returns a pointer to the first element in the array.
Definition: prealloced_array.h:254
 
Element_type & back()
Definition: prealloced_array.h:244
 
Element_type & front()
Definition: prealloced_array.h:247
 
void claim_memory_ownership(bool claim)
Claim memory ownership.
Definition: prealloced_array.h:318
 
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:430
 
iterator end()
Definition: prealloced_array.h:255
 
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:376
 
size_t element_size() const
Definition: prealloced_array.h:225
 
const_iterator end() const
Definition: prealloced_array.h:257
 
External m_ext
Definition: prealloced_array.h:637
 
int m_inline_size
Definition: prealloced_array.h:624
 
const Element_type * const_iterator
Definition: prealloced_array.h:117
 
size_t size_type
Definition: prealloced_array.h:113
 
void adjust_size(int delta)
Definition: prealloced_array.h:99
 
Element_type m_buff[Prealloc]
Definition: prealloced_array.h:638
 
const char * p
Definition: ctype-mb.cc:1237
 
static Bigint * diff(Bigint *a, Bigint *b, Stack_alloc *alloc)
Definition: dtoa.cc:1080
 
#define MY_WME
Definition: my_sys.h:123
 
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
 
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:177
 
Header for compiler-dependent features.
 
Some integer typedefs for easier portability.
 
#define MYF(v)
Definition: my_inttypes.h:97
 
void * my_malloc(PSI_memory_key key, size_t size, int flags)
Allocates size bytes of memory.
Definition: my_memory.cc:57
 
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
 
Common header for many mysys elements.
 
Performance schema instrumentation interface.
 
void my_claim(const void *ptr, bool claim)
Definition: my_malloc.cc:458
 
static MEM_ROOT mem
Definition: sql_servers.cc:99
 
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:642
 
Definition: prealloced_array.h:630
 
size_t m_alloced_size
Definition: prealloced_array.h:632
 
size_t m_alloced_capacity
Definition: prealloced_array.h:633
 
Element_type * m_array_ptr
Definition: prealloced_array.h:631
 
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:42
 
int n
Definition: xcom_base.cc:509