performance efficiencies

This commit is contained in:
Jeff Young 2023-12-18 18:45:02 +00:00
parent 1c73d3d967
commit cfa55d958a
3 changed files with 48 additions and 47 deletions

View File

@ -185,8 +185,8 @@ void BACK_ANNOTATE::getPcbModulesFromString( const std::string& aPayload )
continue;
// Fields are of the format "(field (name "name") "12345")
const auto fieldName = field.second.get_child_optional( "name" );
const auto fieldValue = field.second.back().first;
const auto& fieldName = field.second.get_child_optional( "name" );
const auto& fieldValue = field.second.back().first;
if( !fieldName )
continue;

View File

@ -671,53 +671,54 @@ void SHAPE_POLY_SET::RebuildHolesFromContours()
std::function<void( int, int, std::vector<int> )> process;
process = [&]( int myId, int parentOutlineId, std::vector<int> path )
{
std::set<int> relParents = childToParents[myId];
for( int pathId : path )
{
int erased = relParents.erase( pathId );
wxASSERT( erased > 0 );
}
wxASSERT( relParents.size() == 0 );
int myOutline = -1;
bool isOutline = path.size() % 2 == 0;
if( isOutline )
{
int outlineId = result.AddOutline( contours[myId] );
myOutline = outlineId;
}
else
{
wxASSERT( parentOutlineId != -1 );
result.AddHole( contours[myId], parentOutlineId );
}
auto it = parentToChildren.find( myId );
if( it != parentToChildren.end() )
{
std::vector<int> thisPath = path;
thisPath.emplace_back( myId );
std::set<int> thisPathSet;
thisPathSet.insert( thisPath.begin(), thisPath.end() );
for( int childId : it->second )
process =
[&]( int myId, int parentOutlineId, const std::vector<int>& path )
{
const std::set<int>& childPathSet = childToParents[childId];
std::set<int> relParents = childToParents[myId];
if( thisPathSet != childPathSet )
continue; // Only interested in immediate children
for( int pathId : path )
{
int erased = relParents.erase( pathId );
wxASSERT( erased > 0 );
}
process( childId, myOutline, thisPath );
}
}
};
wxASSERT( relParents.size() == 0 );
int myOutline = -1;
bool isOutline = path.size() % 2 == 0;
if( isOutline )
{
int outlineId = result.AddOutline( contours[myId] );
myOutline = outlineId;
}
else
{
wxASSERT( parentOutlineId != -1 );
result.AddHole( contours[myId], parentOutlineId );
}
auto it = parentToChildren.find( myId );
if( it != parentToChildren.end() )
{
std::vector<int> thisPath = path;
thisPath.emplace_back( myId );
std::set<int> thisPathSet;
thisPathSet.insert( thisPath.begin(), thisPath.end() );
for( int childId : it->second )
{
const std::set<int>& childPathSet = childToParents[childId];
if( thisPathSet != childPathSet )
continue; // Only interested in immediate children
process( childId, myOutline, thisPath );
}
}
};
for( int topParentId : topLevelParents )
{

View File

@ -493,7 +493,7 @@ bool doConvertOutlineToPolygon( std::vector<PCB_SHAPE*>& aShapeList, SHAPE_POLY_
parents.push_back( jj );
}
contourToParentIndexesMap[ii] = parents;
contourToParentIndexesMap[ii] = std::move( parents );
}
// Next add those that are top-level outlines to the SHAPE_POLY_SET