Skip to content

Commit 641e554

Browse files
Reverve componentsMap memory in Circuit::_Optimize()
1 parent aa4591f commit 641e554

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/dspatch/Circuit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ inline void Circuit::_Optimize()
794794
if ( _threadCount != 0 )
795795
{
796796
std::vector<std::vector<DSPatch::Component*>> componentsMap;
797+
componentsMap.reserve( _components.size() );
797798

798799
for ( int i = (int)_components.size() - 1; i >= 0; --i )
799800
{

include/dspatch/Component.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,10 @@ inline void Component::ScanParallel( std::vector<std::vector<DSPatch::Component*
469469
}
470470

471471
// insert component at _scanPosition
472-
if ( _scanPosition >= (int)componentsMap.size() )
472+
if ( _scanPosition == (int)componentsMap.size() )
473473
{
474-
componentsMap.resize( _scanPosition + 1 );
474+
componentsMap.emplace_back( std::vector<DSPatch::Component*>{} );
475+
componentsMap[_scanPosition].reserve( componentsMap.capacity() );
475476
}
476477
componentsMap[_scanPosition].emplace_back( this );
477478
}

0 commit comments

Comments
 (0)