MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / insert

Method insert

src/compactvector.h:72–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 inline const T* end() const { return m_data + m_celem; }
71
72 T* insert(T* where, const T &val)
73 {
74 assert(where >= m_data);
75 size_t idx = where - m_data;
76 if (m_celem >= m_max)
77 {
78 if (m_max < 2)
79 m_max = 2;
80 else
81 m_max = m_max + 4;
82
83 m_data = (T*)zrealloc(m_data, sizeof(T) * m_max, MALLOC_LOCAL);
84 m_max = zmalloc_usable_size(m_data) / sizeof(T);
85 }
86 assert(idx < m_max);
87 where = m_data + idx;
88 memmove(reinterpret_cast<void*>(m_data + idx + 1), reinterpret_cast<const void*>(m_data + idx), (m_celem - idx)*sizeof(T));
89 new(m_data + idx) T(std::move(val));
90 ++m_celem;
91 return where;
92 }
93
94 T &operator[](size_t idx)
95 {

Callers

nothing calls this directly

Calls 2

zreallocFunction · 0.85
zmalloc_usable_sizeFunction · 0.85

Tested by

no test coverage detected