Huw Davies : gdi32: Use a buffer on the stack if the number of points is small.

Alexandre Julliard julliard at winehq.org
Fri Jul 29 10:17:09 CDT 2016


Module: wine
Branch: master
Commit: 22202eae59f95bc370c37da8bb385e019f712a6f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=22202eae59f95bc370c37da8bb385e019f712a6f

Author: Huw Davies <huw at codeweavers.com>
Date:   Fri Jul 29 13:13:05 2016 +0100

gdi32: Use a buffer on the stack if the number of points is small.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/dibdrv/graphics.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/dlls/gdi32/dibdrv/graphics.c b/dlls/gdi32/dibdrv/graphics.c
index 08e777d..3ea39a1 100644
--- a/dlls/gdi32/dibdrv/graphics.c
+++ b/dlls/gdi32/dibdrv/graphics.c
@@ -1239,7 +1239,8 @@ BOOL dibdrv_PolyPolygon( PHYSDEV dev, const POINT *pt, const INT *counts, DWORD
     DC *dc = get_physdev_dc( dev );
     DWORD total, i, pos;
     BOOL ret = TRUE;
-    POINT *points;
+    POINT pt_buf[32];
+    POINT *points = pt_buf;
     HRGN outline = 0, interior = 0;
 
     for (i = total = 0; i < polygons; i++)
@@ -1248,16 +1249,19 @@ BOOL dibdrv_PolyPolygon( PHYSDEV dev, const POINT *pt, const INT *counts, DWORD
         total += counts[i];
     }
 
-    points = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*pt) );
-    if (!points) return FALSE;
+    if (total > sizeof(pt_buf) / sizeof(pt_buf[0]))
+    {
+        points = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*pt) );
+        if (!points) return FALSE;
+    }
     memcpy( points, pt, total * sizeof(*pt) );
     lp_to_dp( dc, points, total );
 
     if (pdev->brush.style != BS_NULL &&
         !(interior = CreatePolyPolygonRgn( points, counts, polygons, dc->polyFillMode )))
     {
-        HeapFree( GetProcessHeap(), 0, points );
-        return FALSE;
+        ret = FALSE;
+        goto done;
     }
 
     if (pdev->pen_uses_region) outline = CreateRectRgn( 0, 0, 0, 0 );
@@ -1289,7 +1293,9 @@ BOOL dibdrv_PolyPolygon( PHYSDEV dev, const POINT *pt, const INT *counts, DWORD
         if (ret) ret = pen_region( pdev, outline );
         DeleteObject( outline );
     }
-    HeapFree( GetProcessHeap(), 0, points );
+
+done:
+    if (points != pt_buf) HeapFree( GetProcessHeap(), 0, points );
     return ret;
 }
 
@@ -1301,7 +1307,8 @@ BOOL dibdrv_PolyPolyline( PHYSDEV dev, const POINT* pt, const DWORD* counts, DWO
     dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
     DC *dc = get_physdev_dc( dev );
     DWORD total, pos, i;
-    POINT *points;
+    POINT pt_buf[32];
+    POINT *points = pt_buf;
     BOOL ret = TRUE;
     HRGN outline = 0;
 
@@ -1311,15 +1318,18 @@ BOOL dibdrv_PolyPolyline( PHYSDEV dev, const POINT* pt, const DWORD* counts, DWO
         total += counts[i];
     }
 
-    points = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*pt) );
-    if (!points) return FALSE;
+    if (total > sizeof(pt_buf) / sizeof(pt_buf[0]))
+    {
+        points = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*pt) );
+        if (!points) return FALSE;
+    }
     memcpy( points, pt, total * sizeof(*pt) );
     lp_to_dp( dc, points, total );
 
     if (pdev->pen_uses_region && !(outline = CreateRectRgn( 0, 0, 0, 0 )))
     {
-        HeapFree( GetProcessHeap(), 0, points );
-        return FALSE;
+        ret = FALSE;
+        goto done;
     }
 
     for (i = pos = 0; i < polylines; i++)
@@ -1336,7 +1346,8 @@ BOOL dibdrv_PolyPolyline( PHYSDEV dev, const POINT* pt, const DWORD* counts, DWO
         DeleteObject( outline );
     }
 
-    HeapFree( GetProcessHeap(), 0, points );
+done:
+    if (points != pt_buf) HeapFree( GetProcessHeap(), 0, points );
     return ret;
 }
 




More information about the wine-cvs mailing list