Browse Source

MeshTools: inline functions should not be heavy.

Returning a vector is as heavy as you can imagine.
simd
Vladimír Vondruš 7 years ago
parent
commit
4deb2a5fe7
  1. 16
      src/Magnum/MeshTools/CombineIndexedArrays.cpp
  2. 12
      src/Magnum/MeshTools/CombineIndexedArrays.h

16
src/Magnum/MeshTools/CombineIndexedArrays.cpp

@ -60,6 +60,10 @@ std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> interleaveAndCombi
return {combinedIndices, interleavedArrays}; return {combinedIndices, interleavedArrays};
} }
}
namespace {
std::vector<UnsignedInt> combineIndexArrays(const std::reference_wrapper<std::vector<UnsignedInt>>* const begin, const std::reference_wrapper<std::vector<UnsignedInt>>* const end) { std::vector<UnsignedInt> combineIndexArrays(const std::reference_wrapper<std::vector<UnsignedInt>>* const begin, const std::reference_wrapper<std::vector<UnsignedInt>>* const end) {
/* Interleave and combine the arrays */ /* Interleave and combine the arrays */
std::vector<UnsignedInt> combinedIndices; std::vector<UnsignedInt> combinedIndices;
@ -83,10 +87,6 @@ std::vector<UnsignedInt> combineIndexArrays(const std::reference_wrapper<std::ve
return combinedIndices; return combinedIndices;
} }
}
namespace {
class IndexHash { class IndexHash {
public: public:
explicit IndexHash(const std::vector<UnsignedInt>& indices, UnsignedInt stride): indices(indices), stride(stride) {} explicit IndexHash(const std::vector<UnsignedInt>& indices, UnsignedInt stride): indices(indices), stride(stride) {}
@ -115,6 +115,14 @@ class IndexEqual {
} }
std::vector<UnsignedInt> combineIndexArrays(const std::vector<std::reference_wrapper<std::vector<UnsignedInt>>>& arrays) {
return combineIndexArrays(&arrays[0], &arrays[0] + arrays.size());
}
std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays) {
return combineIndexArrays(arrays.begin(), arrays.end());
}
std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> combineIndexArrays(const std::vector<UnsignedInt>& interleavedArrays, const UnsignedInt stride) { std::pair<std::vector<UnsignedInt>, std::vector<UnsignedInt>> combineIndexArrays(const std::vector<UnsignedInt>& interleavedArrays, const UnsignedInt stride) {
CORRADE_ASSERT(stride != 0, "MeshTools::combineIndexArrays(): stride can't be zero", {}); CORRADE_ASSERT(stride != 0, "MeshTools::combineIndexArrays(): stride can't be zero", {});
CORRADE_ASSERT(interleavedArrays.size() % stride == 0, "MeshTools::combineIndexArrays(): array size is not divisible by stride", {}); CORRADE_ASSERT(interleavedArrays.size() % stride == 0, "MeshTools::combineIndexArrays(): array size is not divisible by stride", {});

12
src/Magnum/MeshTools/CombineIndexedArrays.h

@ -39,10 +39,6 @@
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {
namespace Implementation {
MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(const std::reference_wrapper<std::vector<UnsignedInt>>* begin, const std::reference_wrapper<std::vector<UnsignedInt>>* end);
}
/** /**
@brief Combine index arrays @brief Combine index arrays
@param[in,out] arrays Index arrays to combine. These arrays are updated @param[in,out] arrays Index arrays to combine. These arrays are updated
@ -85,14 +81,10 @@ This function calls @ref combineIndexArrays(const std::vector<UnsignedInt>&, Uns
internally. See also @ref combineIndexedArrays() which does the vertex data internally. See also @ref combineIndexedArrays() which does the vertex data
reordering automatically. reordering automatically.
*/ */
inline std::vector<UnsignedInt> combineIndexArrays(const std::vector<std::reference_wrapper<std::vector<UnsignedInt>>>& arrays) { MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(const std::vector<std::reference_wrapper<std::vector<UnsignedInt>>>& arrays);
return Implementation::combineIndexArrays(&arrays[0], &arrays[0] + arrays.size());
}
/** @overload */ /** @overload */
inline std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays) { MAGNUM_MESHTOOLS_EXPORT std::vector<UnsignedInt> combineIndexArrays(std::initializer_list<std::reference_wrapper<std::vector<UnsignedInt>>> arrays);
return Implementation::combineIndexArrays(arrays.begin(), arrays.end());
}
/** /**
@brief Combine interleaved index arrays @brief Combine interleaved index arrays

Loading…
Cancel
Save