From 4e07c80645d02aa5560841d64351ecbefa67d0c1 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 19 Dec 2012 15:30:40 +0000 Subject: [PATCH] HIThemeBrushCreateCGColor seems to have become very CPU-expensive, cache the results for better performance git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/utils_osx.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp index 7eb431ad86..da98e5371a 100644 --- a/src/osx/utils_osx.cpp +++ b/src/osx/utils_osx.cpp @@ -246,9 +246,26 @@ CGColorSpaceRef wxMacGetGenericRGBColorSpace() CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) { - CGColorRef color ; - HIThemeBrushCreateCGColor( brush, &color ); - return color; + const int maxcachedbrush = 58+5; // negative indices are for metabrushes, cache down to -5) + int brushindex = brush+5; + if ( brushindex < 0 || brush > brushindex ) + { + CGColorRef color ; + HIThemeBrushCreateCGColor( brush, &color ); + return color; + } + else + { + static bool inited = false; + static CGColorRef themecolors[maxcachedbrush+1]; + if ( !inited ) + { + for ( int i = 0 ; i <= maxcachedbrush ; ++i ) + HIThemeBrushCreateCGColor( i-5, &themecolors[i] ); + inited = true; + } + return CGColorRetain(themecolors[brushindex ]); + } } //--------------------------------------------------------------------------- -- 2.45.2