Implement second-level cache for escaped netnames.

While it's a bit of an encapsulation leak (see comment in
CONNECTION_SUBGRAPH::driverName()), it more than doubles undo/redo
performance in documents with *lots* of nets.
This commit is contained in:
Jeff Young 2023-08-07 21:43:36 +01:00
parent e48a96ecaf
commit c30bdf9ba8
7 changed files with 46 additions and 3 deletions

View File

@ -337,6 +337,7 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const
case SCH_LABEL_T: case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T: case SCH_GLOBAL_LABEL_T:
case SCH_HIER_LABEL_T: case SCH_HIER_LABEL_T:
// NB: any changes here will need corresponding changes in SCH_LABEL_BASE::cacheShownText()
return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( &m_sheet, false ), return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText( &m_sheet, false ),
CTX_NETNAME ); CTX_NETNAME );
@ -357,6 +358,9 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const
const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) const const wxString& CONNECTION_SUBGRAPH::GetNameForDriver( SCH_ITEM* aItem ) const
{ {
if( aItem->HasCachedDriverName() )
return aItem->GetCachedDriverName();
auto it = m_driver_name_cache.find( aItem ); auto it = m_driver_name_cache.find( aItem );
if( it != m_driver_name_cache.end() ) if( it != m_driver_name_cache.end() )

View File

@ -253,6 +253,13 @@ SCH_CONNECTION* SCH_ITEM::GetOrInitConnection( const SCH_SHEET_PATH& aSheet,
} }
const wxString& SCH_ITEM::GetCachedDriverName() const
{
static wxString s_empty;
return s_empty;
}
void SCH_ITEM::SwapData( SCH_ITEM* aItem ) void SCH_ITEM::SwapData( SCH_ITEM* aItem )
{ {
UNIMPLEMENTED_FOR( GetClass() ); UNIMPLEMENTED_FOR( GetClass() );

View File

@ -430,6 +430,9 @@ public:
/// Updates the connection graph for all connections in this item /// Updates the connection graph for all connections in this item
void SetConnectionGraph( CONNECTION_GRAPH* aGraph ); void SetConnectionGraph( CONNECTION_GRAPH* aGraph );
virtual bool HasCachedDriverName() const { return false; }
virtual const wxString& GetCachedDriverName() const;
virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { } virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { }
std::shared_ptr<NETCLASS> GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const; std::shared_ptr<NETCLASS> GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;

View File

@ -691,6 +691,27 @@ bool SCH_LABEL_BASE::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* toke
} }
bool SCH_LABEL_BASE::HasCachedDriverName() const
{
return !HasTextVars();
}
const wxString& SCH_LABEL_BASE::GetCachedDriverName() const
{
return m_cached_driver_name;
}
void SCH_LABEL_BASE::cacheShownText()
{
EDA_TEXT::cacheShownText();
if( !HasTextVars() )
m_cached_driver_name = EscapeString( EDA_TEXT::GetShownText( true, 0 ), CTX_NETNAME );
}
wxString SCH_LABEL_BASE::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText, wxString SCH_LABEL_BASE::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
int aDepth ) const int aDepth ) const
{ {

View File

@ -156,6 +156,9 @@ public:
return GetShownText( nullptr, aAllowExtraText, aDepth ); return GetShownText( nullptr, aAllowExtraText, aDepth );
} }
bool HasCachedDriverName() const override;
const wxString& GetCachedDriverName() const override;
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override; void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
INSPECT_RESULT Visit( INSPECTOR inspector, void* testData, INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
@ -231,6 +234,9 @@ public:
*/ */
virtual bool AutoRotateOnPlacementSupported() const = 0; virtual bool AutoRotateOnPlacementSupported() const = 0;
protected:
void cacheShownText() override;
protected: protected:
std::vector<SCH_FIELD> m_fields; std::vector<SCH_FIELD> m_fields;
@ -241,6 +247,8 @@ protected:
bool m_autoRotateOnPlacement = false; bool m_autoRotateOnPlacement = false;
mutable COLOR4D m_lastResolvedColor; mutable COLOR4D m_lastResolvedColor;
wxString m_cached_driver_name;
}; };

View File

@ -356,8 +356,8 @@ wxString SCH_TEXT::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraTe
if( aPath ) if( aPath )
sheet = aPath->Last(); sheet = aPath->Last();
else if( Schematic() ) else if( SCHEMATIC* schematic = Schematic() )
sheet = Schematic()->CurrentSheet().Last(); sheet = schematic->CurrentSheet().Last();
std::function<bool( wxString* )> textResolver = std::function<bool( wxString* )> textResolver =
[&]( wxString* token ) -> bool [&]( wxString* token ) -> bool

View File

@ -368,7 +368,7 @@ protected:
virtual const KIFONT::METRICS& getFontMetrics() const; virtual const KIFONT::METRICS& getFontMetrics() const;
void cacheShownText(); virtual void cacheShownText();
/** /**
* Print each line of this EDA_TEXT. * Print each line of this EDA_TEXT.