Skip to content

Commit

Permalink
RingDelayBufferTest: eliminate spanFromPtrLen
Browse files Browse the repository at this point in the history
This commit avoids multiple span creation from the input buffer.
Instead of that, the span is created once and stored in the variable.
  • Loading branch information
davidchocholaty committed Aug 30, 2022
1 parent e1c6e8a commit c501fd2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/test/ringdelaybuffer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ TEST_F(RingDelayBufferTest, ReadWriteNoDelayTest) {
const CSAMPLE thirdExpectedResult[] = {-100.0, 100.0, -99.0, 99.0};

mixxx::SampleBuffer output(numSamples);

std::span<CSAMPLE> outputSpan = output.span();
std::span<CSAMPLE> inputBufferSpan = mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples);

EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
inputBufferSpan),
numSamples);
EXPECT_EQ(m_pRingDelayBuffer->read(
outputSpan, 0),
Expand All @@ -71,7 +73,7 @@ TEST_F(RingDelayBufferTest, ReadWriteNoDelayTest) {

// Write and read over one ring.
EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
inputBufferSpan
numSamples);
EXPECT_EQ(m_pRingDelayBuffer->read(
outputSpan, 0),
Expand All @@ -91,11 +93,13 @@ TEST_F(RingDelayBufferTest, ReadWriteDelayTest) {
const CSAMPLE thirdExpectedResult[] = {-50.0, 50.0, -99.0, 99.0};

mixxx::SampleBuffer output(numSamples);

std::span<CSAMPLE> outputSpan = output.span();
std::span<CSAMPLE> inputBufferSpan = mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples);

// Read without delay.
EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
inputBufferSpan
numSamples);
EXPECT_EQ(m_pRingDelayBuffer->read(
outputSpan, 0),
Expand All @@ -114,7 +118,7 @@ TEST_F(RingDelayBufferTest, ReadWriteDelayTest) {

// Fill the second half of the delay buffer with the first input data.
EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
inputBufferSpan
numSamples);

// Read with delay (not circle around).
Expand Down

0 comments on commit c501fd2

Please sign in to comment.