PIVector2D removeColumn memmove optimization
This commit is contained in:
@@ -1219,14 +1219,21 @@ public:
|
||||
//! \sa removeRow(), PIVector::remove()
|
||||
inline PIVector2D<T> & removeColumn(size_t col) {
|
||||
if (col >= cols_ || rows_ == 0) return *this;
|
||||
PIVector2D<T> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user