From 8a26b6174db31f8f1c0e9b30c96c130a86268715 Mon Sep 17 00:00:00 2001 From: "andrey.bychkov" Date: Fri, 27 Feb 2026 01:49:30 +0300 Subject: [PATCH] PIVector2D removeColumn memmove optimization --- libs/main/containers/pivector2d.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libs/main/containers/pivector2d.h b/libs/main/containers/pivector2d.h index dbc80322..d48a8925 100644 --- a/libs/main/containers/pivector2d.h +++ b/libs/main/containers/pivector2d.h @@ -1219,14 +1219,21 @@ public: //! \sa removeRow(), PIVector::remove() inline PIVector2D & removeColumn(size_t col) { if (col >= cols_ || rows_ == 0) return *this; - PIVector2D result(rows_, cols_ - 1); for (size_t r = 0; r < rows_; ++r) { - for (size_t c = 0, nc = 0; c < cols_; ++c) { - if (c == col) continue; - result.element(r, nc++) = element(r, c); + T * dst = mat.data(r * (cols_ - 1)); + T * src = mat.data(r * cols_); + if (col > 0) { + memmove(dst, src, col * sizeof(T)); + dst += col; + src += col; + } + size_t remaining = (cols_ - 1) - col; + if (remaining > 0) { + memmove(dst, src + 1, remaining * sizeof(T)); } } - swap(result); + cols_--; + mat.resize(rows_ * cols_); return *this; }