Eeschema: Reduced LoadSymbol calls in PlaceSymbol

Check early if a symbol is not unique - before calling SchGetLibSymbol
and in SchGetLibSymbol checks the cache before calling LoadSymbol.

This speeds up opening the symbol browser significantly when having lots
of symbols in the design that needs to be polled from a database

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18826
This commit is contained in:
Martin Berglund
2024-12-20 16:54:22 +00:00
committed by Seth Hillbrand
parent cf71e5707e
commit 337f3da7c9
+11 -17
View File
@@ -308,13 +308,8 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
SYMBOL_LIB* cache = PROJECT_SCH::SchLibs( &m_frame->Prj() )->GetCacheLibrary();
auto compareByLibID =
[]( const LIB_SYMBOL* aFirst, const LIB_SYMBOL* aSecond ) -> bool
{
return aFirst->LibId().Format() < aSecond->LibId().Format();
};
std::set<LIB_SYMBOL*, decltype( compareByLibID )> part_list( compareByLibID );
std::set<UTF8> unique_libid;
std::vector<PICKED_SYMBOL> alreadyPlaced;
for( SCH_SHEET_PATH& sheet : sheets )
{
@@ -324,22 +319,21 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
continue;
SCH_SYMBOL* s = static_cast<SCH_SYMBOL*>( item );
if( !unique_libid.insert( s->GetLibId().Format() ).second )
continue;
LIB_SYMBOL* libSymbol = SchGetLibSymbol( s->GetLibId(), libs, cache );
if( libSymbol )
part_list.insert( libSymbol );
{
PICKED_SYMBOL pickedSymbol;
pickedSymbol.LibId = libSymbol->GetLibId();
alreadyPlaced.push_back( pickedSymbol );
}
}
}
std::vector<PICKED_SYMBOL> alreadyPlaced;
for( LIB_SYMBOL* libSymbol : part_list )
{
PICKED_SYMBOL pickedSymbol;
pickedSymbol.LibId = libSymbol->GetLibId();
alreadyPlaced.push_back( pickedSymbol );
}
// Pick the symbol to be placed
bool footprintPreviews = m_frame->eeconfig()->m_Appearance.footprint_preview;
PICKED_SYMBOL sel = m_frame->PickSymbolFromLibrary( &filter, *historyList,