1 |
/* |
/* |
2 |
* Copyright (c) 2014 - 2019 Christian Schoenebeck |
* Copyright (c) 2014 - 2021 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
116 |
* @param count - amount of elements to be removed |
* @param count - amount of elements to be removed |
117 |
*/ |
*/ |
118 |
inline void remove(size_t index, size_t count = 1) { |
inline void remove(size_t index, size_t count = 1) { |
119 |
if (index >= m_size || index + count > m_size) |
if (index >= m_size) |
120 |
return; |
return; |
121 |
|
// special case: no elements behind the removed elements, so nothing |
122 |
|
// to move |
123 |
|
if (index + count >= m_size) { |
124 |
|
m_size = index; |
125 |
|
return; |
126 |
|
} |
127 |
// don't use memmove() here! Since it is not RT safe with all libc |
// don't use memmove() here! Since it is not RT safe with all libc |
128 |
// implementations and on all architectures |
// implementations and on all architectures |
129 |
for (size_t i = 0; i < count; ++i) |
const size_t n = m_size - index - count; |
130 |
|
for (size_t i = 0; i < n; ++i) |
131 |
m_data[index + i] = m_data[index + i + count]; |
m_data[index + i] = m_data[index + i + count]; |
132 |
m_size -= count; |
m_size -= count; |
133 |
} |
} |