From b7bc4ea43e5f21ecea5710d3a6d157cb8fe5b1d2 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 24 Aug 2013 15:03:59 +0200 Subject: [PATCH] Pcbnew: speedup netlist read, when some footprints are not found, by caching the non-existent footprint names, which are searched only once in libs. When a non existent footprint is used by many components, this footprint was previoulsy searched in libs for each component, which is very time consumming. --- pcbnew/netlist.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index 6df4c7e10e..d0a80154e5 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -4,8 +4,10 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2011 Jean-Pierre Charras. - * Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2013 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2013 Wayne Stambaugh + * Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -167,10 +169,15 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) { wxString msg; wxString lastFootprintLibName; + wxArrayString nofoundFootprints; // A list of footprints used in netlist + // but not found in any library + // to avoid a full search in all libs + // each time a non existent footprint is needed COMPONENT* component; MODULE* module = 0; MODULE* fpOnBoard; + if( aNetlist.IsEmpty() ) return; @@ -230,6 +237,23 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) { module = NULL; + // Speed up the search: a search for a non existent footprint + // is hightly costly in time becuse the full set of libs is read. + // So it should be made only once. + // Therefore search in not found list first: + bool alreadySearched = false; + for( unsigned ii = 0; ii < nofoundFootprints.GetCount(); ii++ ) + { + if( component->GetFootprintName() == nofoundFootprints[ii] ) + { + alreadySearched = true; + break; + } + } + + if( alreadySearched ) + continue; + for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ ) { fn = wxFileName( wxEmptyString, g_LibraryNames[ii], @@ -259,7 +283,7 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) } } - if( module == NULL ) + if( module == NULL && !alreadySearched ) { if( aReporter ) { @@ -270,6 +294,8 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter ) aReporter->Report( msg ); } + nofoundFootprints.Add( component->GetFootprintName() ); + continue; } }