From f8095fd31a84a36b26922eddde947dc03e4375a2 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Thu, 9 Nov 2023 17:12:39 +0300 Subject: [PATCH] Optimize CADSTAR library parsing. -60% loading time. --- .../cadstar/cadstar_archive_parser.cpp | 37 +++++++++++++------ .../cadstar/cadstar_sch_archive_loader.cpp | 4 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/common/plugins/cadstar/cadstar_archive_parser.cpp b/common/plugins/cadstar/cadstar_archive_parser.cpp index af85453745..6131348855 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.cpp +++ b/common/plugins/cadstar/cadstar_archive_parser.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020-2021 Roberto Fernandez Bautista - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.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 as published by the @@ -2421,20 +2421,28 @@ void CADSTAR_ARCHIVE_PARSER::PARTNAMECOL::Parse( XNODE* aNode, PARSER_CONTEXT* a void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd( XNODE* aNode, wxString aValue ) { - wxString result; - int numAttributes = 0; + static const wxString c_numAttributes = wxT( "numAttributes" ); - if( aNode->GetAttribute( wxT( "numAttributes" ), &result ) ) + wxString result; + long numAttributes = 0; + + if( aNode->GetAttribute( c_numAttributes, &result ) ) { - numAttributes = wxAtoi( result ); - aNode->DeleteAttribute( wxT( "numAttributes" ) ); + numAttributes = wxAtol( result ); + aNode->DeleteAttribute( c_numAttributes ); ++numAttributes; } - aNode->AddAttribute( wxT( "numAttributes" ), wxString::Format( wxT( "%i" ), numAttributes ) ); +#if wxUSE_UNICODE_WCHAR + std::wstring numAttrStr = std::to_wstring( numAttributes ); +#else + std::string numAttrStr = std::to_string( numAttributes ); +#endif + + aNode->AddAttribute( c_numAttributes, numAttrStr ); wxString paramName = wxT( "attr" ); - paramName << numAttributes; + paramName << numAttrStr; aNode->AddAttribute( paramName, aValue ); } @@ -2574,9 +2582,16 @@ bool CADSTAR_ARCHIVE_PARSER::IsValidAttribute( wxXmlAttribute* aAttribute ) wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( XNODE* aNode, unsigned int aID, bool aIsRequired ) { - wxString attrName, retVal; - attrName = "attr"; - attrName << aID; +#if wxUSE_UNICODE_WCHAR + std::wstring idStr = std::to_wstring( aID ); +#else + std::string idStr = std::to_string( aID ); +#endif + + wxString attrName = wxS( "attr" ); + attrName << idStr; + + wxString retVal; if( !aNode->GetAttribute( attrName, &retVal ) ) { diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 99098f2fb2..a3c92681d1 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -2051,10 +2051,12 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices( const std::vect shape->SetUnit( aGateNumber ); shape->SetStroke( STROKE_PARAMS( aLineThickness, PLOT_DASH_TYPE::SOLID ) ); - aSymbol->AddDrawItem( shape ); + aSymbol->AddDrawItem( shape, false ); prev = cur; } + + aSymbol->GetDrawItems().sort(); }