Skip to content
Snippets Groups Projects
Commit 45a5aa15 authored by Spiros Tsalikis's avatar Spiros Tsalikis
Browse files

vtkAMRDataInternals: Improve performance when adding datasets

Better complexity reduces the number of internal swaps needed.
parent fcf99326
No related branches found
No related tags found
No related merge requests found
......@@ -41,13 +41,9 @@ void vtkAMRDataInternals::PrintSelf(ostream& os, vtkIndent indent)
void vtkAMRDataInternals::Insert(unsigned int index, vtkUniformGrid* grid)
{
this->Blocks.emplace_back(index, grid);
int i = static_cast<int>(this->Blocks.size()) - 2;
while (i >= 0 && this->Blocks[i].Index > this->Blocks[i + 1].Index)
{
std::swap(this->Blocks[i], this->Blocks[i + 1]);
i--;
}
const auto it = std::lower_bound(this->Blocks.begin(), this->Blocks.end(), index,
[](const Block& block, unsigned int idx) { return block.Index < idx; });
this->Blocks.insert(it, Block(index, grid));
}
vtkUniformGrid* vtkAMRDataInternals::GetDataSet(unsigned int compositeIndex)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment