- use a straightforward binary search for GetSegmentIndexAtBeat
- fix a bug where adding a segment with the same value as the old one removes the old one [it should just skip adding the new segment].
This commit is contained in:
+19
-10
@@ -112,21 +112,30 @@ int TimingData::GetSegmentIndexAtRow(TimingSegmentType tst, int iRow ) const
|
|||||||
{
|
{
|
||||||
const vector<TimingSegment*> &vSegs = GetTimingSegments(tst);
|
const vector<TimingSegment*> &vSegs = GetTimingSegments(tst);
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if( vSegs.empty() )
|
if( vSegs.empty() )
|
||||||
return INVALID_INDEX;
|
return INVALID_INDEX;
|
||||||
|
|
||||||
// seek to the last segment that goes into effect before iRow.
|
int min = 0, max = vSegs.size() - 1;
|
||||||
// UGLY: vSegs.size() is cast to an int because its normal return type
|
int l = min, r = max;
|
||||||
// is size_t, but when it equals zero, subtracting 1 wraps around.
|
while( l <= r )
|
||||||
for( ; i < int(vSegs.size()) - 1; ++i )
|
|
||||||
{
|
{
|
||||||
if( iRow < vSegs[i+1]->GetRow() )
|
int m = ( l + r ) / 2;
|
||||||
break;
|
if( ( m == min || vSegs[m]->GetRow() <= iRow ) && ( m == max || iRow < vSegs[m + 1]->GetRow() ) )
|
||||||
|
{
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
else if( vSegs[m]->GetRow() <= iRow )
|
||||||
|
{
|
||||||
|
l = m + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = m - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return INVALID_INDEX; // this should not be reached. :(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ts_less : binary_function <TimingSegment*, TimingSegment*, bool>
|
struct ts_less : binary_function <TimingSegment*, TimingSegment*, bool>
|
||||||
@@ -342,7 +351,7 @@ void TimingData::AddSegment( const TimingSegment *seg )
|
|||||||
prev = vSegs[index - 1];
|
prev = vSegs[index - 1];
|
||||||
|
|
||||||
// if true, this is redundant segment change
|
// if true, this is redundant segment change
|
||||||
if( (*prev) == (*seg) )
|
if( prev != cur && (*prev) == (*seg) )
|
||||||
{
|
{
|
||||||
EraseSegment( vSegs, index, cur );
|
EraseSegment( vSegs, index, cur );
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user