Optimization removeAll and removeWhere in PIVector and PIDeque
This commit is contained in:
@@ -1630,11 +1630,14 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIDeque<T> & removeAll(const T & e) {
|
||||
for (size_t i = 0; i < pid_size; ++i) {
|
||||
if (pid_data[i + pid_start] == e) {
|
||||
remove(i);
|
||||
--i;
|
||||
ssize_t j = indexOf(e);
|
||||
if (j != -1) {
|
||||
for (size_t i = j + 1; i < pid_size; ++i) {
|
||||
if (pid_data[i + pid_start] != e) {
|
||||
pid_data[j++ + pid_start] = std::move(pid_data[i + pid_start]);
|
||||
}
|
||||
}
|
||||
remove(j, pid_size - j);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -1651,11 +1654,14 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIDeque<T> & removeWhere(std::function<bool(const T & e)> test) {
|
||||
for (size_t i = 0; i < pid_size; ++i) {
|
||||
if (test(pid_data[i + pid_start])) {
|
||||
remove(i);
|
||||
--i;
|
||||
ssize_t j = indexWhere(test);
|
||||
if (j != -1) {
|
||||
for (size_t i = j + 1; i < pid_size; ++i) {
|
||||
if (!test(pid_data[i + pid_start])) {
|
||||
pid_data[j++ + pid_start] = std::move(pid_data[i + pid_start]);
|
||||
}
|
||||
}
|
||||
remove(j, pid_size - j);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1555,11 +1555,14 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIVector<T> & removeAll(const T & e) {
|
||||
for (ssize_t i = 0; i < size_s(); ++i) {
|
||||
if (piv_data[i] == e) {
|
||||
remove(i);
|
||||
--i;
|
||||
ssize_t j = indexOf(e);
|
||||
if (j != -1) {
|
||||
for (size_t i = j + 1; i < piv_size; ++i) {
|
||||
if (piv_data[i] != e) {
|
||||
piv_data[j++] = std::move(piv_data[i]);
|
||||
}
|
||||
}
|
||||
remove(j, piv_size - j);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -1576,11 +1579,14 @@ public:
|
||||
//! \endcode
|
||||
//! \~\sa \a remove(), \a removeOne(), \a removeWhere()
|
||||
inline PIVector<T> & removeWhere(std::function<bool(const T & e)> test) {
|
||||
for (ssize_t i = 0; i < size_s(); ++i) {
|
||||
if (test(piv_data[i])) {
|
||||
remove(i);
|
||||
--i;
|
||||
ssize_t j = indexWhere(test);
|
||||
if (j != -1) {
|
||||
for (size_t i = j + 1; i < piv_size; ++i) {
|
||||
if (!test(piv_data[i])) {
|
||||
piv_data[j++] = std::move(piv_data[i]);
|
||||
}
|
||||
}
|
||||
remove(j, piv_size - j);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user