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:
parent
e48a96ecaf
commit
c30bdf9ba8
|
@ -337,6 +337,7 @@ wxString CONNECTION_SUBGRAPH::driverName( SCH_ITEM* aItem ) const
|
|||
case SCH_LABEL_T:
|
||||
case SCH_GLOBAL_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 ),
|
||||
CTX_NETNAME );
|
||||
|
||||
|
@ -357,6 +358,9 @@ wxString CONNECTION_SUBGRAPH::driverName( 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 );
|
||||
|
||||
if( it != m_driver_name_cache.end() )
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
UNIMPLEMENTED_FOR( GetClass() );
|
||||
|
|
|
@ -430,6 +430,9 @@ public:
|
|||
/// Updates the connection graph for all connections in this item
|
||||
void SetConnectionGraph( CONNECTION_GRAPH* aGraph );
|
||||
|
||||
virtual bool HasCachedDriverName() const { return false; }
|
||||
virtual const wxString& GetCachedDriverName() const;
|
||||
|
||||
virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { }
|
||||
|
||||
std::shared_ptr<NETCLASS> GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
|
||||
|
|
|
@ -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,
|
||||
int aDepth ) const
|
||||
{
|
||||
|
|
|
@ -156,6 +156,9 @@ public:
|
|||
return GetShownText( nullptr, aAllowExtraText, aDepth );
|
||||
}
|
||||
|
||||
bool HasCachedDriverName() const override;
|
||||
const wxString& GetCachedDriverName() const override;
|
||||
|
||||
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
|
||||
|
||||
INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
|
||||
|
@ -231,6 +234,9 @@ public:
|
|||
*/
|
||||
virtual bool AutoRotateOnPlacementSupported() const = 0;
|
||||
|
||||
protected:
|
||||
void cacheShownText() override;
|
||||
|
||||
protected:
|
||||
std::vector<SCH_FIELD> m_fields;
|
||||
|
||||
|
@ -241,6 +247,8 @@ protected:
|
|||
bool m_autoRotateOnPlacement = false;
|
||||
|
||||
mutable COLOR4D m_lastResolvedColor;
|
||||
|
||||
wxString m_cached_driver_name;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -356,8 +356,8 @@ wxString SCH_TEXT::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraTe
|
|||
|
||||
if( aPath )
|
||||
sheet = aPath->Last();
|
||||
else if( Schematic() )
|
||||
sheet = Schematic()->CurrentSheet().Last();
|
||||
else if( SCHEMATIC* schematic = Schematic() )
|
||||
sheet = schematic->CurrentSheet().Last();
|
||||
|
||||
std::function<bool( wxString* )> textResolver =
|
||||
[&]( wxString* token ) -> bool
|
||||
|
|
|
@ -368,7 +368,7 @@ protected:
|
|||
|
||||
virtual const KIFONT::METRICS& getFontMetrics() const;
|
||||
|
||||
void cacheShownText();
|
||||
virtual void cacheShownText();
|
||||
|
||||
/**
|
||||
* Print each line of this EDA_TEXT.
|
||||
|
|
Loading…
Reference in New Issue