diff --git a/libs/main/containers/pideque.h b/libs/main/containers/pideque.h index 4414b063..4cd8af5c 100644 --- a/libs/main/containers/pideque.h +++ b/libs/main/containers/pideque.h @@ -1630,11 +1630,14 @@ public: //! \endcode //! \~\sa \a remove(), \a removeOne(), \a removeWhere() inline PIDeque & 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 & removeWhere(std::function 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; } diff --git a/libs/main/containers/pivector.h b/libs/main/containers/pivector.h index 910f6cc9..23dee95c 100644 --- a/libs/main/containers/pivector.h +++ b/libs/main/containers/pivector.h @@ -1555,11 +1555,14 @@ public: //! \endcode //! \~\sa \a remove(), \a removeOne(), \a removeWhere() inline PIVector & 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 & removeWhere(std::function 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; }