1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-24 16:01:16 +02:00

Rewrite Sequence::FindBlock using size_t variables for indices

This commit is contained in:
Paul Licameli 2016-08-20 20:58:13 -04:00
parent 49e699b1df
commit a1d930322c

View File

@ -1051,16 +1051,15 @@ int Sequence::FindBlock(sampleCount pos) const
int numBlocks = mBlock.size(); int numBlocks = mBlock.size();
sampleCount lo = 0, loSamples = 0; size_t lo = 0, hi = numBlocks, guess;
sampleCount hi = numBlocks, hiSamples = mNumSamples; sampleCount loSamples = 0, hiSamples = mNumSamples;
sampleCount guess;
while (true) { while (true) {
//this is not a binary search, but a //this is not a binary search, but a
//dictionary search where we guess something smarter than the binary division //dictionary search where we guess something smarter than the binary division
//of the unsearched area, since samples are usually proportional to block file number. //of the unsearched area, since samples are usually proportional to block file number.
const double frac = double(pos - loSamples) / (hiSamples - loSamples); const double frac = double(pos - loSamples) / (hiSamples - loSamples);
guess = std::min(hi - 1, lo + sampleCount(frac * (hi - lo))); guess = std::min(hi - 1, lo + size_t(frac * (hi - lo)));
const SeqBlock &block = mBlock[guess]; const SeqBlock &block = mBlock[guess];
wxASSERT(block.f->GetLength() > 0); wxASSERT(block.f->GetLength() > 0);