PIVector and PIDeque some code clean
This commit is contained in:
@@ -205,14 +205,13 @@ public:
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize))
|
||||
deleteT(pid_data + pid_start, pid_size);
|
||||
dealloc();
|
||||
_reset();
|
||||
}
|
||||
|
||||
//! \~english Assign operator.
|
||||
//! \~russian Оператор присваивания.
|
||||
inline PIDeque<T> & operator =(const PIDeque<T> & other) {
|
||||
if (this == &other) return *this;
|
||||
deleteT(pid_data + pid_start, pid_size);
|
||||
clear();
|
||||
alloc_forward(other.pid_size);
|
||||
newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size);
|
||||
return *this;
|
||||
@@ -1175,7 +1174,7 @@ public:
|
||||
PIDeque<T> getRange(size_t index, size_t count) const {
|
||||
if (index >= pid_size || count == 0) return PIDeque<T>();
|
||||
if (index + count > pid_size) count = pid_size - index;
|
||||
return PIDeque(&(pid_data[pid_start + index]), count);
|
||||
return PIDeque(pid_data + pid_start + index, count);
|
||||
}
|
||||
|
||||
//! \~english Clear array, remove all elements.
|
||||
@@ -1189,7 +1188,7 @@ public:
|
||||
!std::is_trivially_copyable<T1>::value
|
||||
, int>::type = 0>
|
||||
inline PIDeque<T> & clear() {
|
||||
deleteT(&(pid_data[pid_start]), pid_size);
|
||||
deleteT(pid_data + pid_start, pid_size);
|
||||
pid_size = 0;
|
||||
pid_start = (pid_rsize - pid_size) / 2;
|
||||
return *this;
|
||||
@@ -1277,7 +1276,7 @@ public:
|
||||
inline PIDeque<T> & resize(size_t new_size, const T & e = T()) {
|
||||
if (new_size == 0) return clear();
|
||||
if (new_size < pid_size) {
|
||||
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
|
||||
deleteT(pid_data + pid_start + new_size, pid_size - new_size);
|
||||
pid_size = new_size;
|
||||
}else if (new_size > pid_size) {
|
||||
expand(new_size, e);
|
||||
@@ -1299,7 +1298,7 @@ public:
|
||||
inline PIDeque<T> & resize(size_t new_size, std::function<T(size_t i)> f) {
|
||||
if (new_size == 0) return clear();
|
||||
if (new_size < pid_size) {
|
||||
deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size);
|
||||
deleteT(pid_data + pid_start + new_size, pid_size - new_size);
|
||||
pid_size = new_size;
|
||||
} else if (new_size > pid_size) {
|
||||
expand(new_size, f);
|
||||
@@ -1366,12 +1365,12 @@ public:
|
||||
alloc_forward(pid_size + 1);
|
||||
if (index < pid_size - 1) {
|
||||
size_t os = pid_size - index - 1;
|
||||
memmove((void*)(&(pid_data[index + pid_start + 1])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start + index + 1), (const void*)(pid_data + pid_start + index), os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + 1, -1);
|
||||
if (index > 0) {
|
||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start), (const void*)(pid_data + pid_start + 1), index * sizeof(T));
|
||||
}
|
||||
}
|
||||
elementNew(pid_data + pid_start + index, e);
|
||||
@@ -1392,12 +1391,12 @@ public:
|
||||
alloc_forward(pid_size + 1);
|
||||
if (index < pid_size - 1) {
|
||||
size_t os = pid_size - index - 1;
|
||||
memmove((void*)(&(pid_data[index + pid_start + 1])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start + index + 1), (const void*)(pid_data + pid_start + index), os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + 1, -1);
|
||||
if (index > 0) {
|
||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start), (const void*)(pid_data + pid_start + 1), index * sizeof(T));
|
||||
}
|
||||
}
|
||||
elementNew(pid_data + pid_start + index, std::move(e));
|
||||
@@ -1423,12 +1422,12 @@ public:
|
||||
ssize_t os = pid_size - index;
|
||||
alloc_forward(pid_size + v.pid_size);
|
||||
if (os > 0) {
|
||||
memmove((void*)(&(pid_data[index + pid_start + v.pid_size])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start + index + v.pid_size), (const void*)(pid_data + pid_start + index), os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + v.pid_size, -v.pid_size);
|
||||
if (index > 0) {
|
||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + v.pid_size])), index * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start), (const void*)(pid_data + pid_start + v.pid_size), index * sizeof(T));
|
||||
}
|
||||
}
|
||||
newT(pid_data + pid_start + index, v.pid_data + v.pid_start, v.pid_size);
|
||||
@@ -1446,17 +1445,18 @@ public:
|
||||
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||
//! \~\sa \a append(), \a prepend(), \a remove()
|
||||
inline PIDeque<T> & insert(size_t index, std::initializer_list<T> init_list) {
|
||||
if (init_list.size() == 0) return *this;
|
||||
bool dir = init_list.size() > pid_size ? true : (index >= pid_rsize / 2 ? true : false);
|
||||
if (dir) {
|
||||
ssize_t os = ssize_t(pid_size) - index;
|
||||
alloc_forward(pid_size + init_list.size());
|
||||
if (os > 0) {
|
||||
memmove((void*)(&(pid_data[index + pid_start + init_list.size()])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start + index + init_list.size()), (const void*)(pid_data + pid_start + index), os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
alloc_backward(pid_size + init_list.size(), -init_list.size());
|
||||
if (index > 0) {
|
||||
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + init_list.size()])), index * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start), (const void*)(pid_data + pid_start + init_list.size()), index * sizeof(T));
|
||||
}
|
||||
}
|
||||
newT(pid_data + pid_start + index, init_list.begin(), init_list.size());
|
||||
@@ -1476,20 +1476,20 @@ public:
|
||||
if (count == 0) return *this;
|
||||
if (index + count >= pid_size) {
|
||||
if (index < pid_size) {
|
||||
deleteT(&(pid_data[index + pid_start]), pid_size - index);
|
||||
deleteT(pid_data + pid_start + index, pid_size - index);
|
||||
pid_size = index;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
size_t os = pid_size - index - count;
|
||||
deleteT(&(pid_data[index + pid_start]), count);
|
||||
deleteT(pid_data + pid_start + index, count);
|
||||
if (os <= index) {
|
||||
if (os > 0) {
|
||||
memmove((void*)(&(pid_data[index + pid_start])), (const void*)(&(pid_data[index + pid_start + count])), os * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start + index), (const void*)(pid_data + pid_start + index + count), os * sizeof(T));
|
||||
}
|
||||
} else {
|
||||
if (index > 0) {
|
||||
memmove((void*)(&(pid_data[pid_start + count])), (const void*)(&(pid_data[pid_start])), index * sizeof(T));
|
||||
memmove((void*)(pid_data + pid_start + count), (const void*)(pid_data + pid_start), index * sizeof(T));
|
||||
}
|
||||
pid_start += count;
|
||||
}
|
||||
@@ -1738,6 +1738,7 @@ public:
|
||||
//! [списка инициализации C++11](https://ru.cppreference.com/w/cpp/utility/initializer_list).
|
||||
//! \~\sa \a push_back()
|
||||
inline PIDeque<T> & push_back(std::initializer_list<T> init_list) {
|
||||
if (init_list.size() == 0) return *this;
|
||||
size_t ps = pid_size;
|
||||
alloc_forward(pid_size + init_list.size());
|
||||
newT(pid_data + pid_start + ps, init_list.begin(), init_list.size());
|
||||
@@ -2073,6 +2074,7 @@ public:
|
||||
template <typename ST>
|
||||
inline PIDeque<ST> toType() const {
|
||||
PIDeque<ST> ret(pid_size);
|
||||
ret.reserve(pid_size);
|
||||
for (size_t i = 0; i < pid_size; ++i) {
|
||||
ret[i] = ST(pid_data[i + pid_start]);
|
||||
}
|
||||
@@ -2511,8 +2513,8 @@ private:
|
||||
|
||||
inline size_t asize(ssize_t s) {
|
||||
if (s <= 0) return 0;
|
||||
if (pid_rsize + pid_rsize >= size_t(s) && pid_rsize < size_t(s)) {
|
||||
return pid_rsize + pid_rsize;
|
||||
if (pid_rsize * 2 >= size_t(s) && pid_rsize < size_t(s)) {
|
||||
return pid_rsize * 2;
|
||||
}
|
||||
size_t t = _PIContainerConstants<T>::minCountPoT();
|
||||
size_t s_ = s - 1;
|
||||
|
||||
Reference in New Issue
Block a user