Browse Source

MeshTools: don't allocate and memcpy zeros in interleave().

We have std::memset for that. What the hell I was thinking back then.

Found when trying to get rid of as many naked allocations and deletions
as possible. Also improved the test with some ASCII-art documentation.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
c7ef09d5dc
  1. 4
      src/MeshTools/Interleave.h
  2. 3
      src/MeshTools/Test/InterleaveTest.cpp

4
src/MeshTools/Interleave.h

@ -113,11 +113,9 @@ class Interleave {
/* Fill gap with zeros */
std::size_t writeOne(char* startingOffset, std::size_t gap) {
char* data = new char[gap]();
for(std::size_t i = 0; i != _attributeCount; ++i)
memcpy(startingOffset+i*_stride, data, gap);
std::memset(startingOffset+i*_stride, 0, gap);
delete[] data;
return gap;
}

3
src/MeshTools/Test/InterleaveTest.cpp

@ -122,13 +122,16 @@ void InterleaveTest::writeGaps() {
CORRADE_COMPARE(attributeCount, std::size_t(3));
CORRADE_COMPARE(stride, std::size_t(12));
std::size_t size = attributeCount*stride;
if(!Utility::Endianness::isBigEndian()) {
/* byte, _____________gap, int___________________, short_____, _______gap */
CORRADE_COMPARE(std::vector<char>(data, data+size), (std::vector<char>{
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00
}));
} else {
/* byte, _____________gap, ___________________int, _____short, _______gap */
CORRADE_COMPARE(std::vector<char>(data, data+size), (std::vector<char>{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00,

Loading…
Cancel
Save