mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 23:00:06 +02:00
One less indirection accessing InvalidRegion
This commit is contained in:
parent
507cee7ee5
commit
5de27ac36f
@ -145,21 +145,22 @@ public:
|
|||||||
for(size_t i=0;i<mRegions.size();i++)
|
for(size_t i=0;i<mRegions.size();i++)
|
||||||
{
|
{
|
||||||
//if the regions intersect OR are pixel adjacent
|
//if the regions intersect OR are pixel adjacent
|
||||||
if(mRegions[i]->start <= invalEnd+1
|
InvalidRegion ®ion = mRegions[i];
|
||||||
&& mRegions[i]->end >= invalStart-1)
|
if(region.start <= invalEnd+1
|
||||||
|
&& region.end >= invalStart-1)
|
||||||
{
|
{
|
||||||
//take the union region
|
//take the union region
|
||||||
if(mRegions[i]->start > invalStart)
|
if(region.start > invalStart)
|
||||||
mRegions[i]->start = invalStart;
|
region.start = invalStart;
|
||||||
if(mRegions[i]->end < invalEnd)
|
if(region.end < invalEnd)
|
||||||
mRegions[i]->end = invalEnd;
|
region.end = invalEnd;
|
||||||
added=true;
|
added=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this bit doesn't make sense because it assumes we add in order - now we go backwards after the initial OD finishes
|
//this bit doesn't make sense because it assumes we add in order - now we go backwards after the initial OD finishes
|
||||||
// //this array is sorted by start/end points and has no overlaps. If we've passed all possible intersections, insert. The array will remain sorted.
|
// //this array is sorted by start/end points and has no overlaps. If we've passed all possible intersections, insert. The array will remain sorted.
|
||||||
// if(mRegions[i]->end < invalStart)
|
// if(region.end < invalStart)
|
||||||
// {
|
// {
|
||||||
// InvalidRegion* newRegion = new InvalidRegion(invalStart,invalEnd);
|
// InvalidRegion* newRegion = new InvalidRegion(invalStart,invalEnd);
|
||||||
// mRegions.insert(mRegions.begin()+i,newRegion);
|
// mRegions.insert(mRegions.begin()+i,newRegion);
|
||||||
@ -170,7 +171,7 @@ public:
|
|||||||
|
|
||||||
if(!added)
|
if(!added)
|
||||||
{
|
{
|
||||||
InvalidRegion* newRegion = new InvalidRegion(invalStart,invalEnd);
|
InvalidRegion newRegion(invalStart,invalEnd);
|
||||||
mRegions.insert(mRegions.begin(),newRegion);
|
mRegions.insert(mRegions.begin(),newRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,24 +180,24 @@ public:
|
|||||||
for(size_t i=1;i<mRegions.size();i++)
|
for(size_t i=1;i<mRegions.size();i++)
|
||||||
{
|
{
|
||||||
//if the regions intersect OR are pixel adjacent
|
//if the regions intersect OR are pixel adjacent
|
||||||
if(mRegions[i]->start <= mRegions[i-1]->end+1
|
InvalidRegion ®ion = mRegions[i];
|
||||||
&& mRegions[i]->end >= mRegions[i-1]->start-1)
|
InvalidRegion &prevRegion = mRegions[i - 1];
|
||||||
|
if(region.start <= prevRegion.end+1
|
||||||
|
&& region.end >= prevRegion.start-1)
|
||||||
{
|
{
|
||||||
//take the union region
|
//take the union region
|
||||||
if(mRegions[i]->start > mRegions[i-1]->start)
|
if(region.start > prevRegion.start)
|
||||||
mRegions[i]->start = mRegions[i-1]->start;
|
region.start = prevRegion.start;
|
||||||
if(mRegions[i]->end < mRegions[i-1]->end)
|
if(region.end < prevRegion.end)
|
||||||
mRegions[i]->end = mRegions[i-1]->end;
|
region.end = prevRegion.end;
|
||||||
|
|
||||||
//now we must delete the previous region
|
|
||||||
delete mRegions[i-1];
|
|
||||||
mRegions.erase(mRegions.begin()+i-1);
|
mRegions.erase(mRegions.begin()+i-1);
|
||||||
//musn't forget to reset cursor
|
//musn't forget to reset cursor
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we are past the end of the region we added, we are past the area of regions that might be oversecting.
|
//if we are past the end of the region we added, we are past the area of regions that might be oversecting.
|
||||||
if(mRegions[i]->start > invalEnd)
|
if(region.start > invalEnd)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -205,15 +206,11 @@ public:
|
|||||||
|
|
||||||
//lock before calling these in a section. unlock after finished.
|
//lock before calling these in a section. unlock after finished.
|
||||||
int GetNumInvalidRegions() const {return mRegions.size();}
|
int GetNumInvalidRegions() const {return mRegions.size();}
|
||||||
int GetInvalidRegionStart(int i) const {return mRegions[i]->start;}
|
int GetInvalidRegionStart(int i) const {return mRegions[i].start;}
|
||||||
int GetInvalidRegionEnd(int i) const {return mRegions[i]->end;}
|
int GetInvalidRegionEnd(int i) const {return mRegions[i].end;}
|
||||||
|
|
||||||
void ClearInvalidRegions()
|
void ClearInvalidRegions()
|
||||||
{
|
{
|
||||||
for(size_t i =0;i<mRegions.size();i++)
|
|
||||||
{
|
|
||||||
delete mRegions[i];
|
|
||||||
}
|
|
||||||
mRegions.clear();
|
mRegions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +254,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<InvalidRegion*> mRegions;
|
std::vector<InvalidRegion> mRegions;
|
||||||
ODLock mRegionsMutex;
|
ODLock mRegionsMutex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user