]> git.saurik.com Git - wxWidgets.git/commitdiff
Only call GetTextMetrics() in wxDC::GetTextExtent() if necessary.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 18 Dec 2009 14:47:18 +0000 (14:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 18 Dec 2009 14:47:18 +0000 (14:47 +0000)
A micro-optimization: avoid ::GetTextMetrics() call if we don't use its
results (as is the case if neither descent nor external leading were
requested).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62926 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/dc.cpp

index 54b5e781fa6614e1e4497225a042bb375101e528..675447fe3a235d07d1d32c3c551033503dbf97fc 100644 (file)
@@ -1772,17 +1772,21 @@ void wxMSWDCImpl::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y
     }
 #endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
 
-    TEXTMETRIC tm;
-    ::GetTextMetrics(GetHdc(), &tm);
-
     if (x)
         *x = sizeRect.cx;
     if (y)
         *y = sizeRect.cy;
-    if (descent)
-        *descent = tm.tmDescent;
-    if (externalLeading)
-        *externalLeading = tm.tmExternalLeading;
+
+    if ( descent || externalLeading )
+    {
+        TEXTMETRIC tm;
+        ::GetTextMetrics(GetHdc(), &tm);
+
+        if (descent)
+            *descent = tm.tmDescent;
+        if (externalLeading)
+            *externalLeading = tm.tmExternalLeading;
+    }
 
     if ( hfontOld )
     {