Fix symbol sorting routine to be determinant.

This commit is contained in:
Jeff Young 2023-09-12 16:52:39 +01:00
parent 7d1dbb77c3
commit a63025733a
1 changed files with 10 additions and 6 deletions

View File

@ -97,19 +97,23 @@ void SCH_SEXPR_PLUGIN_CACHE::Save( const std::optional<bool>& aOpt )
std::vector<LIB_SYMBOL*> orderedSymbols;
for( const std::pair<const wxString, LIB_SYMBOL*>& parent : m_symbols )
orderedSymbols.push_back( parent.second );
for( const auto& [ name, symbol ] : m_symbols )
{
if( symbol )
orderedSymbols.push_back( symbol );
}
// Library must be ordered by inheritance depth.
std::sort( orderedSymbols.begin(), orderedSymbols.end(),
[]( const LIB_SYMBOL* aLhs, const LIB_SYMBOL* aRhs )
{
wxCHECK( aLhs && aRhs, false );
if( aLhs->GetInheritanceDepth() < aRhs->GetInheritanceDepth() )
return true;
unsigned int lhDepth = aLhs->GetInheritanceDepth();
unsigned int rhDepth = aRhs->GetInheritanceDepth();
if( lhDepth == rhDepth )
return aLhs->GetName() < aRhs->GetName();
return lhDepth < rhDepth;
} );
for( LIB_SYMBOL* symbol : orderedSymbols )