From 00c1f471e4dfbf459e8d7cd4f8f7fa7118a6b6c4 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 827bd9d0b3..cf2e58e6af 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -330,35 +330,29 @@ 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->GetLibId().Format() < aSecond->GetLibId().Format(); - }; - - std::set part_list( compareByLibID ); + std::set unique_libid; + std::vector alreadyPlaced; for( SCH_SHEET_PATH& sheet : hierarchy ) { for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) ) { 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,