From 8d4ab945002c78e4f37ca5e10c89df1ec7c61c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 17 May 2021 17:11:23 +0200 Subject: [PATCH] Use -1 as uninitialized value for m_expanderWidth Use -1, not 0, for the not-yet-computed value. Prevents CPU-intensive recomputation when the calculated size _is_ zero - e.g. because the column is hidden. --- src/osx/cocoa/dataview.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index d5939b62ec..3b603a36e9 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2092,7 +2092,7 @@ wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer, ), m_DataSource(NULL), m_OutlineView([[wxCocoaOutlineView alloc] init]), - m_expanderWidth(0) + m_expanderWidth(-1) { // initialize scrollview (the outline view is part of a scrollview): NSScrollView* scrollview = (NSScrollView*) GetWXWidget(); @@ -2254,7 +2254,7 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) m_view(view), m_column(columnIndex), m_indent(0), - m_expander(0), + m_expander(-1), m_tableColumn(column) { // account for indentation in the column with expander @@ -2275,7 +2275,7 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) if ( m_indent ) cellWidth += m_indent * [m_view levelForRow:row]; - if ( m_expander == 0 && m_tableColumn == [m_view outlineTableColumn] ) + if ( m_expander == -1 && m_tableColumn == [m_view outlineTableColumn] ) { NSRect rc = [m_view frameOfOutlineCellAtRow:row]; m_expander = ceil(rc.origin.x + rc.size.width); @@ -2366,10 +2366,10 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) // there might not necessarily be an expander in the rows we've examined above so let's // globally store the expander width for re-use because it should always be the same - if ( m_expanderWidth == 0 ) + if ( m_expanderWidth == -1 ) m_expanderWidth = calculator.GetExpanderWidth(); - [column setWidth:calculator.GetMaxWidth() + m_expanderWidth]; + [column setWidth:calculator.GetMaxWidth() + wxMax(0, m_expanderWidth)]; } //