Make a minor optimization in Mac wxDisplay::GetFromWindow()

Call GetContentScaleFactor() only once, which doesn't cost anything and
could be minutely faster on systems with multiple displays.
This commit is contained in:
Vadim Zeitlin
2020-08-15 00:27:07 +02:00
parent 08a63c3b49
commit 41142dff20

View File

@@ -255,11 +255,12 @@ int wxDisplayFactoryMacOSX::GetFromWindow(const wxWindow *window)
err = CGGetDisplaysWithRect(r, theCount, theIDs.get(), &theCount); err = CGGetDisplaysWithRect(r, theCount, theIDs.get(), &theCount);
wxASSERT(err == CGDisplayNoErr); wxASSERT(err == CGDisplayNoErr);
const double scaleWindow = tlw->GetContentScaleFactor();
for ( int i = 0 ; i < theCount; ++i ) for ( int i = 0 ; i < theCount; ++i )
{ {
// find a screen intersecting having the same contentScale as the window itself // find a screen intersecting having the same contentScale as the window itself
double scale = wxGetScaleFactor(theIDs[i]); double scale = wxGetScaleFactor(theIDs[i]);
if ( fabs(scale - tlw->GetContentScaleFactor() ) < 0.01 ) if ( fabs(scale - scaleWindow) < 0.01 )
{ {
return wxOSXGetDisplayFromID(theIDs[i]); return wxOSXGetDisplayFromID(theIDs[i]);
} }