From c61af21da8dc5191ef9269624ceac4668dfb007a Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 14 Oct 2021 09:12:40 -0400 Subject: [PATCH] Eeschema: don't stat files when updating title bar text. The tests for file existence and write status perform two file stats which cause performance issues on slow network shares. Now the file state is determined at load time and stored in the SCH_SCREEN object so file access is no longer required. Fixes https://gitlab.com/kicad/code/kicad/-/issues/9343 --- eeschema/sch_edit_frame.cpp | 12 ++++++++---- eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp | 5 +++++ eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp | 6 ++++++ eeschema/sch_screen.cpp | 4 +++- eeschema/sch_screen.h | 11 +++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index ce23080ba1..a255857c1c 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1231,16 +1231,20 @@ void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_SCREEN* aScreen, SCH_ITEM* void SCH_EDIT_FRAME::UpdateTitle() { + SCH_SCREEN* screen = GetScreen(); + + wxCHECK( screen, /* void */ ); + wxString title; - if( !GetScreen()->GetFileName().IsEmpty() ) + if( !screen->GetFileName().IsEmpty() ) { - wxFileName fn( Prj().AbsolutePath( GetScreen()->GetFileName() ) ); + wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) ); bool readOnly = false; bool unsaved = false; - if( fn.IsOk() && fn.FileExists() ) - readOnly = !fn.IsFileWritable(); + if( fn.IsOk() && screen->FileExists() ) + readOnly = screen->IsReadOnly(); else unsaved = true; diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 4dfff1788b..d3b24822dc 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -519,6 +519,9 @@ void SCH_SEXPR_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) m_error += ioe.What(); } + aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() ); + aSheet->GetScreen()->SetFileExists( true ); + // This was moved out of the try{} block so that any sheets definitionsthat // the plugin fully parsed before the exception was raised will be loaded. for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) ) @@ -594,6 +597,8 @@ void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEM m_out = &formatter; // no ownership Format( aSheet ); + + aSheet->GetScreen()->SetFileExists( true ); } diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index 2121711491..5e74497c72 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -744,6 +744,9 @@ void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) m_error += ioe.What(); } + aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() ); + aSheet->GetScreen()->SetFileExists( true ); + for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) ) { wxCHECK2( aItem->Type() == SCH_SHEET_T, continue ); @@ -1864,6 +1867,7 @@ std::shared_ptr SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader { buf.clear(); parseUnquotedString( buf, aReader, line, &line, true ); + if( buf.Len() > 0 ) { busAlias->AddMember( buf ); @@ -1895,6 +1899,8 @@ void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHE m_out = &formatter; // no ownership Format( aSheet ); + + aSheet->GetScreen()->SetFileExists( true ); } diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 8dabe8bcf1..e9ce910b3e 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -66,7 +66,9 @@ SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) : BASE_SCREEN( aParent, SCH_SCREEN_T ), m_fileFormatVersionAtLoad( 0 ), - m_paper( wxT( "A4" ) ) + m_paper( wxT( "A4" ) ), + m_isReadOnly( false ), + m_fileExists( false ) { m_modification_sync = 0; m_refCount = 0; diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 9e2a4fc617..7e998becdc 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -144,6 +144,12 @@ public: const wxString& GetFileName() const { return m_fileName; } + void SetFileReadOnly( bool aIsReadOnly ) { m_isReadOnly = aIsReadOnly; } + bool IsReadOnly() const { return m_isReadOnly; } + + void SetFileExists( bool aFileExists ) { m_fileExists = aFileExists; } + bool FileExists() const { return m_fileExists; } + const wxPoint& GetAuxOrigin() const { return m_aux_origin; } void SetAuxOrigin( const wxPoint& aPosition ) { m_aux_origin = aPosition; } @@ -512,6 +518,11 @@ private: bool m_zoomInitialized; // Set to true once the zoom value is initialized with // `InitZoom()`. + bool m_isReadOnly; ///< Read only status of the screen file. + + ///< Flag to indicate the file associated with this screen has been created. + bool m_fileExists; + /// List of bus aliases stored in this screen. std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases;