PIDeque important performance fix

This commit is contained in:
2021-06-11 19:10:13 +03:00
parent ef80a72e38
commit f03781f898
3 changed files with 102 additions and 66 deletions

View File

@@ -228,6 +228,7 @@ public:
inline PIDeque<T> & clear() {
PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size)
pid_size = 0;
pid_start = (pid_rsize - pid_size) / 2;
return *this;
}
@@ -258,6 +259,8 @@ public:
if (new_size < pid_size) {
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
pid_size = new_size;
if (new_size == 0)
pid_start = (pid_rsize - pid_size) / 2;
}
if (new_size > pid_size) {
size_t os = pid_size;
@@ -291,6 +294,8 @@ public:
}
inline PIDeque<T> & insert(size_t index, const T & v = T()) {
if (index == pid_size) return push_back(v);
PIINTROSPECTION_CONTAINER_USED(T, 1)
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
if (dir) {
alloc(pid_size + 1, true);
@@ -303,11 +308,12 @@ public:
if (index > 0)
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
}
PIINTROSPECTION_CONTAINER_USED(T, 1)
elementNew(pid_data + pid_start + index, v);
return *this;
}
inline PIDeque<T> & insert(size_t index, T && v) {
if (index == pid_size) return push_back(v);
PIINTROSPECTION_CONTAINER_USED(T, 1)
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
if (dir) {
alloc(pid_size + 1, true);
@@ -320,7 +326,6 @@ public:
if (index > 0)
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
}
PIINTROSPECTION_CONTAINER_USED(T, 1)
elementNew(pid_data + pid_start + index, std::move(v));
return *this;
}