Author: spouliot
Date: 2006-09-18 13:32:09 -0400 (Mon, 18 Sep 2006)
New Revision: 65589

Modified:
   trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
   trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs
Log:
2006-09-18  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * Graphics.cs: Reorder instructions in MeasureString methods to avoid
        allocations before checking for quick exit case (null/String.Empty 
        text or throwing execptions).



Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2006-09-18 
17:29:47 UTC (rev 65588)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog     2006-09-18 
17:32:09 UTC (rev 65589)
@@ -1,3 +1,9 @@
+2006-09-18  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * Graphics.cs: Reorder instructions in MeasureString methods to avoid
+       allocations before checking for quick exit case (null/String.Empty 
+       text or throwing execptions).
+
 2006-09-11  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * ImageConverter.cs: Fixed ConvertTo to deal with null values (#79331)

Modified: trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs   2006-09-18 
17:29:47 UTC (rev 65588)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Graphics.cs   2006-09-18 
17:32:09 UTC (rev 65589)
@@ -1899,23 +1899,22 @@
                
                public SizeF MeasureString (string text, Font font)
                {
-                       return MeasureString (text, font, new Size (0, 0));
+                       return MeasureString (text, font, SizeF.Empty);
                }
 
                
                public SizeF MeasureString (string text, Font font, SizeF 
layoutArea)
                {
-                       int charactersFitted, linesFilled;
-                       RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (0, 0, 
layoutArea.Width,
-                                                         layoutArea.Height);
-
                        if (text == null || text.Length == 0)
                                return SizeF.Empty;
 
                        if (font == null)
                                throw new ArgumentNullException ("font");
 
+                       int charactersFitted, linesFilled;
+                       RectangleF boundingBox = new RectangleF ();
+                       RectangleF rect = new RectangleF (0, 0, 
layoutArea.Width, layoutArea.Height);
+
                        Status status = GDIPlus.GdipMeasureString 
(nativeObject, text, text.Length,
                                                                   
font.NativeObject, ref rect,
                                                                   IntPtr.Zero, 
out boundingBox,
@@ -1928,16 +1927,16 @@
                
                public SizeF MeasureString (string text, Font font, int width)
                {                               
-                       RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (0, 0, width, 999999);
-                       int charactersFitted, linesFilled;
-
                        if (text == null || text.Length == 0)
                                return SizeF.Empty;
 
                        if (font == null)
                                throw new ArgumentNullException ("font");
 
+                       RectangleF boundingBox = new RectangleF ();
+                       RectangleF rect = new RectangleF (0, 0, width, 999999);
+                       int charactersFitted, linesFilled;
+
                        Status status = GDIPlus.GdipMeasureString 
(nativeObject, text, text.Length, 
                                                                   
font.NativeObject, ref rect,
                                                                   IntPtr.Zero, 
out boundingBox,
@@ -1968,22 +1967,20 @@
                public SizeF MeasureString (string text, Font font, PointF 
origin,
                                            StringFormat stringFormat)
                {
-                       RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (origin.X, origin.Y, 
0, 0);
-                       int charactersFitted, linesFilled;
-
                        if (text == null || text.Length == 0)
                                return SizeF.Empty;
 
                        if (font == null)
                                throw new ArgumentNullException ("font");
 
-                       if (stringFormat == null)
-                               stringFormat = new StringFormat ();
+                       RectangleF boundingBox = new RectangleF ();
+                       RectangleF rect = new RectangleF (origin.X, origin.Y, 
0, 0);
+                       int charactersFitted, linesFilled;
 
+                       IntPtr format = (stringFormat == null) ? IntPtr.Zero : 
stringFormat.NativeObject;
+
                        Status status = GDIPlus.GdipMeasureString 
(nativeObject, text, text.Length, 
-                                                                  
font.NativeObject, ref rect,
-                                                                  
stringFormat.NativeObject, 
+                                                                  
font.NativeObject, ref rect, format, 
                                                                   out 
boundingBox,
                                                                   out 
charactersFitted,
                                                                   out 
linesFilled);
@@ -1997,8 +1994,6 @@
                                            StringFormat stringFormat, out int 
charactersFitted,
                                            out int linesFilled)
                {       
-                       RectangleF boundingBox = new RectangleF ();
-                       RectangleF rect = new RectangleF (0, 0, 
layoutArea.Width, layoutArea.Height);
                        charactersFitted = 0;
                        linesFilled = 0;
 
@@ -2008,12 +2003,13 @@
                        if (font == null)
                                throw new ArgumentNullException ("font");
 
-                       if (stringFormat == null)
-                               stringFormat = new StringFormat ();
+                       RectangleF boundingBox = new RectangleF ();
+                       RectangleF rect = new RectangleF (0, 0, 
layoutArea.Width, layoutArea.Height);
 
+                       IntPtr format = (stringFormat == null) ? IntPtr.Zero : 
stringFormat.NativeObject;
+
                        Status status = GDIPlus.GdipMeasureString 
(nativeObject, text, text.Length, 
-                                                                  
font.NativeObject, ref rect,
-                                                                  
stringFormat.NativeObject,
+                                                                  
font.NativeObject, ref rect, format,
                                                                   out 
boundingBox,
                                                                   out 
charactersFitted,
                                                                   out 
linesFilled);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to