Commit c40f5917 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Pcbnew: speedup netlist read, when some footprints are not found, by caching...

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.
parent 8cca89ff
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -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 <dick@softplc.com>
 * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
 * 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;
            }
        }