From 337f3da7c9fa66621f61e947a84dcd5c0eecdfbd Mon Sep 17 00:00:00 2001 From: Martin Berglund Date: Thu, 24 Oct 2024 22:59:49 +0000 Subject: [PATCH] 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 --- eeschema/tools/sch_drawing_tools.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 8700be2bc8..419ec21671 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -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 part_list( compareByLibID ); + std::set unique_libid; + std::vector 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( 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 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,