add caching in windows/sysparams.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This patch drastically improves the performance of repeated calls 
to SystemParametersInfoA() with SPI_GETICONTITLELOGFONT[31] and 
SPI_GETNONCLIENTMETRICS[41].  In tracking down why Idag.exe (IDA)
had such performance problems when starting up and during other
operations I noticed that these two calls are being called repeatedly.
And each call caused windows.ini to be opened.  A lot of work to retrieve 
the same values over and over again.  The performance on my machine went 
from ~2 minute delays to ~5 second delays while running Idag.exe.

Please email me with comments/flames as I'm not on the mailing lists.
If this isn't a proper fix I'd like to discuss what the correct way 
to do it would be.

Changelog:
    Kurt Mahan <kmahan_at_xmission.com>
    Cache data for SystemParametersInfoA(SPI_GETICONTITLELOGFONT) and
    SystemParametersInfoA(SPI_GETNONCLIENTMETRICS).

--- windows/sysparams.c	31 Oct 2003 04:18:55 -0000	1.56
+++ windows/sysparams.c	1 Dec 2003 01:12:44 -0000
@@ -149,6 +149,17 @@
 static BOOL screen_reader = FALSE;
 static BOOL screensaver_running = FALSE;
 
+// caching for #31 - SPI_GETICONTITLELOGFONT
+static int cache31_seen = 0;
+static int cache31_height = 0;
+static BYTE cache31_charset = 0;
+static char cache31_name[LF_FACESIZE];
+
+// caching for #41 - SPI_GETNONCLIENTMETRICS
+static int cache41_seen = 0;
+static int cache41_height = 0;
+static char cache41_name[LF_FACESIZE];
+
 /***********************************************************************
  *		GetTimerResolution (USER.14)
  */
@@ -1092,24 +1103,39 @@
 
         if (!pvParam) return FALSE;
 
-	/*
-	 * The 'default GDI fonts' seems to be returned.
-	 * If a returned font is not a correct font in your environment,
-	 * please try to fix objects/gdiobj.c at first.
-	 */
-	SYSPARAMS_GetGUIFont( &lfDefault );
-
-	GetProfileStringA( "Desktop", "IconTitleFaceName",
-			   lfDefault.lfFaceName,
-			   lpLogFont->lfFaceName, LF_FACESIZE );
-	lpLogFont->lfHeight = -GetProfileIntA( "Desktop", "IconTitleSize", 11 );
+        if ( cache31_seen )
+        {
+                // use cached values
+                lpLogFont->lfHeight = cache31_height;
+                memcpy( lpLogFont->lfFaceName, cache31_name, LF_FACESIZE );
+	            lpLogFont->lfCharSet = cache31_charset;
+        }
+        else
+        {
+                /*
+                 * The 'default GDI fonts' seems to be returned.
+                 * If a returned font is not a correct font in your environment,
+                 * please try to fix objects/gdiobj.c at first.
+                 */
+                SYSPARAMS_GetGUIFont( &lfDefault );
+                GetProfileStringA( "Desktop", "IconTitleFaceName",
+                                   lfDefault.lfFaceName,
+                                   lpLogFont->lfFaceName, LF_FACESIZE );
+                lpLogFont->lfHeight = -GetProfileIntA( "Desktop", "IconTitleSize", 11 );
+	        lpLogFont->lfCharSet = lfDefault.lfCharSet; /* at least 'charset' should not be hard-coded */
+                // setup cache
+                cache31_seen = 1;
+                cache31_height = lpLogFont->lfHeight;
+                cache31_charset = lpLogFont->lfCharSet;
+                memcpy( cache31_name, lpLogFont->lfFaceName, LF_FACESIZE );
+        }
+
 	lpLogFont->lfWidth = 0;
 	lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
 	lpLogFont->lfWeight = FW_NORMAL;
 	lpLogFont->lfItalic = FALSE;
 	lpLogFont->lfStrikeOut = FALSE;
 	lpLogFont->lfUnderline = FALSE;
-	lpLogFont->lfCharSet = lfDefault.lfCharSet; /* at least 'charset' should not be hard-coded */
 	lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
 	lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
 	lpLogFont->lfPitchAndFamily = DEFAULT_PITCH;
@@ -1246,10 +1272,25 @@
 
 	    /* menu font metrics */
 	    SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfMenuFont), 0 );
-	    GetProfileStringA( "Desktop", "MenuFont",
-			       (TWEAK_WineLook > WIN31_LOOK) ? lpnm->lfCaptionFont.lfFaceName : "System",
-			       lpnm->lfMenuFont.lfFaceName, LF_FACESIZE );
-	    lpnm->lfMenuFont.lfHeight = -GetProfileIntA( "Desktop", "MenuFontSize", 11 );
+
+        if ( cache41_seen )
+        {
+            memcpy( lpnm->lfMenuFont.lfFaceName, cache41_name, LF_FACESIZE );
+	        lpnm->lfMenuFont.lfHeight = cache41_height;
+        }
+        else
+        { 
+            GetProfileStringA( "Desktop", "MenuFont",
+			                   (TWEAK_WineLook > WIN31_LOOK) ? lpnm->lfCaptionFont.lfFaceName : "System",
+			                   lpnm->lfMenuFont.lfFaceName, LF_FACESIZE );
+	        lpnm->lfMenuFont.lfHeight = -GetProfileIntA( "Desktop", "MenuFontSize", 11 );
+
+            // setup cache
+            cache41_seen = 1;
+            cache41_height = lpnm->lfMenuFont.lfHeight;
+            memcpy( cache41_name, lpnm->lfMenuFont.lfFaceName, LF_FACESIZE );
+        }
+
 	    lpnm->lfMenuFont.lfWeight = (TWEAK_WineLook > WIN31_LOOK) ? FW_NORMAL : FW_BOLD;
 
 	    /* status bar font metrics */


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux