Marginal performance improvements.

This commit is contained in:
Jeff Young 2022-08-25 15:03:44 +01:00
parent f99761e5bd
commit 86944c4f9f
7 changed files with 34 additions and 35 deletions

View File

@ -105,7 +105,10 @@ namespace std
{
std::size_t operator()( const PTR_PTR_CACHE_KEY& k ) const
{
return hash<void*>()( k.A ) ^ hash<void*>()( k.B );
constexpr std::size_t prime = 2166136261u;
return reinterpret_cast<uintptr_t>( k.A ) * prime
^ reinterpret_cast<uintptr_t>( k.B ) * prime;
}
};
@ -114,9 +117,10 @@ namespace std
{
std::size_t operator()( const PTR_LAYER_CACHE_KEY& k ) const
{
constexpr std::size_t prime = 19937;
constexpr std::size_t prime = 2166136261u;
return hash<void*>()( k.A ) ^ ( hash<int>()( k.Layer ) * prime );
return reinterpret_cast<uintptr_t>( k.A ) * prime
^ hash<int>()( k.Layer ) * prime;
}
};
@ -125,9 +129,11 @@ namespace std
{
std::size_t operator()( const PTR_PTR_LAYER_CACHE_KEY& k ) const
{
constexpr std::size_t prime = 19937;
constexpr std::size_t prime = 2166136261u;
return hash<void*>()( k.A ) ^ hash<void*>()( k.B ) ^ ( hash<int>()( k.Layer ) * prime );
return reinterpret_cast<uintptr_t>( k.A ) * prime
^ reinterpret_cast<uintptr_t>( k.B ) * prime
^ hash<int>()( k.Layer ) * prime;
}
};
}

View File

@ -39,6 +39,7 @@
#include <geometry/shape_segment.h>
#include <math/vector2d.h>
#include "geometry/shape_null.h"
#include "board.h"
/**
* Implement an R-tree for fast spatial and layer indexing of connectable items.
@ -208,21 +209,19 @@ public:
* clearance. It's used when looking up the specific item-to-item clearance might be
* expensive and should be deferred till we know we have a possible hit.
*/
int QueryColliding( BOARD_ITEM* aRefItem,
PCB_LAYER_ID aRefLayer,
PCB_LAYER_ID aTargetLayer,
int QueryColliding( BOARD_ITEM* aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer,
std::function<bool( BOARD_ITEM* )> aFilter = nullptr,
std::function<bool( BOARD_ITEM* )> aVisitor = nullptr,
int aClearance = 0 ) const
{
// keep track of BOARD_ITEMs that have been already found to collide (some items
// might be build of COMPOUND/triangulated shapes and a single subshape collision
// means we have a hit)
// keep track of BOARD_ITEMs that have already been found to collide (some items might
// be built of COMPOUND/triangulated shapes and a single subshape collision means we have
// a hit)
std::unordered_set<BOARD_ITEM*> collidingCompounds;
// keep track of results of client filter so we don't ask more than once for compound
// shapes
std::map<BOARD_ITEM*, bool> filterResults;
std::unordered_map<BOARD_ITEM*, bool> filterResults;
EDA_RECT box = aRefItem->GetBoundingBox();
box.Inflate( aClearance );
@ -394,9 +393,10 @@ public:
* @param aLayer Layer to search
* @return vector of overlapping BOARD_ITEMS*
*/
std::set<BOARD_ITEM*> GetObjectsAt( const VECTOR2I& aPt, PCB_LAYER_ID aLayer, int aClearance = 0 )
std::unordered_set<BOARD_ITEM*> GetObjectsAt( const VECTOR2I& aPt, PCB_LAYER_ID aLayer,
int aClearance = 0 )
{
std::set<BOARD_ITEM*> retval;
std::unordered_set<BOARD_ITEM*> retval;
int min[2] = { aPt.x - aClearance, aPt.y - aClearance };
int max[2] = { aPt.x + aClearance, aPt.y + aClearance };
@ -427,11 +427,9 @@ public:
ITEM_WITH_SHAPE* testItem;
};
int QueryCollidingPairs( DRC_RTREE* aRefTree,
std::vector<LAYER_PAIR> aLayerPairs,
std::function<bool( const LAYER_PAIR&,
ITEM_WITH_SHAPE*, ITEM_WITH_SHAPE*,
bool* aCollision )> aVisitor,
int QueryCollidingPairs( DRC_RTREE* aRefTree, std::vector<LAYER_PAIR> aLayerPairs,
std::function<bool( const LAYER_PAIR&, ITEM_WITH_SHAPE*,
ITEM_WITH_SHAPE*, bool* aCollision )> aVisitor,
int aMaxClearance,
std::function<bool(int, int )> aProgressReporter ) const
{
@ -468,7 +466,7 @@ public:
// keep track of BOARD_ITEMs pairs that have been already found to collide (some items
// might be build of COMPOUND/triangulated shapes and a single subshape collision
// means we have a hit)
std::map< std::pair<BOARD_ITEM*, BOARD_ITEM*>, int> collidingCompounds;
std::unordered_map<PTR_PTR_CACHE_KEY, int> collidingCompounds;
int progress = 0;
int count = pairsToVisit.size();

View File

@ -454,7 +454,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances()
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( checkedPairs.count( { a, b } ) )
if( checkedPairs.find( { a, b } ) != checkedPairs.end() )
{
return false;
}
@ -721,7 +721,7 @@ void DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances( )
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( checkedPairs.count( { a, b } ) )
if( checkedPairs.find( { a, b } ) != checkedPairs.end() )
{
return false;
}

View File

@ -190,7 +190,7 @@ bool DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run()
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( checkedPairs.count( { a, b } ) )
if( checkedPairs.find( { a, b } ) != checkedPairs.end() )
{
return false;
}
@ -235,7 +235,7 @@ bool DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run()
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( checkedPairs.count( { a, b } ) )
if( checkedPairs.find( { a, b } ) != checkedPairs.end() )
{
return false;
}

View File

@ -191,7 +191,7 @@ bool DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::Run()
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( checkedPairs.count( { a, b } ) )
if( checkedPairs.find( { a, b } ) != checkedPairs.end() )
{
return false;
}

View File

@ -451,12 +451,11 @@ void DRC_TEST_PROVIDER_SOLDER_MASK::testItemAgainstItems( BOARD_ITEM* aItem,
BOARD_ITEM* a = aItem;
BOARD_ITEM* b = other;
// store canonical order so we don't collide in both directions
// (a:b and b:a)
// store canonical order so we don't collide in both directions (a:b and b:a)
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( m_checkedPairs.count( { a, b, aTargetLayer } ) )
if( m_checkedPairs.find( { a, b, aTargetLayer } ) != m_checkedPairs.end() )
{
return false;
}

View File

@ -2368,11 +2368,7 @@ void FOOTPRINT::CheckOverlappingPads( const std::function<void( const PAD*, cons
if( static_cast<void*>( a ) > static_cast<void*>( b ) )
std::swap( a, b );
if( checkedPairs.count( { a, b } ) )
{
continue;
}
else
if( checkedPairs.find( { a, b } ) == checkedPairs.end() )
{
checkedPairs[ { a, b } ] = 1;
@ -2530,13 +2526,13 @@ void FOOTPRINT::CheckNetTiePadGroups( const std::function<void( const wxString&
{
aErrorHandler( wxString::Format( _( "(net-tie pad group contains unknown pad "
"number %s)" ),
padNumber ) );
padNumber ) );
}
else if( !padNumbers.insert( padNumber ).second )
{
aErrorHandler( wxString::Format( _( "(pad %s appears in more than one net-tie "
"pad group)" ),
padNumber ) );
padNumber ) );
}
}
}