From 03b038ccfe22c79278009c2db948b127550e7392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 16 Mar 2020 19:13:09 +0100 Subject: [PATCH] Trade: use Math::castInto() inside indicesInto(). This code was apparently done before the batch casters were a thing. Now it's no reason to do the same in two places, additionally in the future the castInto() could get SIMD-optimized and this can benefit from that. --- src/Magnum/Trade/MeshData.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Magnum/Trade/MeshData.cpp b/src/Magnum/Trade/MeshData.cpp index 1db25bcfe..0acefcd55 100644 --- a/src/Magnum/Trade/MeshData.cpp +++ b/src/Magnum/Trade/MeshData.cpp @@ -394,27 +394,19 @@ Containers::StridedArrayView2D MeshData::mutableAttribute(MeshAttribute na return mutableAttribute(attributeId); } -namespace { - -template void convertIndices(const Containers::ArrayView data, const Containers::ArrayView destination) { - const auto input = Containers::arrayCast(data); - for(std::size_t i = 0; i != input.size(); ++i) destination[i] = input[i]; -} - -} - void MeshData::indicesInto(const Containers::ArrayView destination) const { CORRADE_ASSERT(isIndexed(), "Trade::MeshData::indicesInto(): the mesh is not indexed", ); CORRADE_ASSERT(destination.size() == indexCount(), "Trade::MeshData::indicesInto(): expected a view with" << indexCount() << "elements but got" << destination.size(), ); - - switch(_indexType) { - case MeshIndexType::UnsignedByte: return convertIndices(_indices, destination); - case MeshIndexType::UnsignedShort: return convertIndices(_indices, destination); - case MeshIndexType::UnsignedInt: return convertIndices(_indices, destination); - } - - CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + auto destination1ui = Containers::arrayCast<2, UnsignedInt>(destination); + + if(_indexType == MeshIndexType::UnsignedInt) + return Utility::copy(Containers::arrayCast(_indices), destination); + else if(_indexType == MeshIndexType::UnsignedShort) + return Math::castInto(Containers::arrayCast<2, const UnsignedShort>(Containers::arrayCast(_indices)), destination1ui); + else if(_indexType == MeshIndexType::UnsignedByte) + return Math::castInto(Containers::arrayCast<2, const UnsignedByte>(Containers::arrayCast(_indices)), destination1ui); + else CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ } Containers::Array MeshData::indicesAsArray() const {