Skip to content

Commit

Permalink
Go back to using [] to flatten vectors
Browse files Browse the repository at this point in the history
Iterators appear to give much slower code, so
revert this change for now.
This reverts commit 656311f.
  • Loading branch information
benmwebb committed Feb 6, 2024
1 parent 14d20e7 commit b1976e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
8 changes: 0 additions & 8 deletions modules/kernel/include/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ class Vector : public Value
V::insert(V::end(), o.begin(), o.end());
return *this;
}

//! Allocate enough storage for `new_cap` elements
/** Makes sure that the vector can contain `new_cap` elements without needing
a reallocation. This does not change the reported size of the vector. */
void reserve(unsigned int new_cap) {
V::reserve(new_cap);
}

#if !defined(IMP_DOXYGEN) && !defined(SWIG)
void show(std::ostream &out = std::cout) const {
out << "[";
Expand Down
14 changes: 8 additions & 6 deletions modules/kernel/include/internal/container_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,23 @@ inline bool is_valid(
template <unsigned int D>
inline ParticlesTemp flatten(const Vector<
Array<D, WeakPointer<Particle>, Particle *> > &in) {
ParticlesTemp ret;
ret.reserve(in.size() * D);
ParticlesTemp ret(in.size() * D);
for (unsigned int i = 0; i < in.size(); ++i) {
ret += in[i];
for (unsigned int j = 0; j < D; ++j) {
ret[i * D + j] = in[i][j];
}
}
return ret;
}

template <unsigned int D>
inline ParticleIndexes flatten(
const Vector<Array<D, ParticleIndex> > &in) {
ParticleIndexes ret;
ret.reserve(in.size() * D);
ParticleIndexes ret(in.size() * D);
for (unsigned int i = 0; i < in.size(); ++i) {
ret += in[i];
for (unsigned int j = 0; j < D; ++j) {
ret[i * D + j] = in[i][j];
}
}
return ret;
}
Expand Down

0 comments on commit b1976e1

Please sign in to comment.