[PATCH 1/3] gdi32: Use a buffer on the stack if the number of points is small.
Huw Davies
huw at codeweavers.com
Fri Jul 29 07:13:05 CDT 2016
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
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 ba5fb70..e6d65e1 100644
--- a/dlls/gdi32/dibdrv/graphics.c
+++ b/dlls/gdi32/dibdrv/graphics.c
@@ -1240,7 +1240,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++)
@@ -1249,16 +1250,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 );
@@ -1290,7 +1294,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;
}
@@ -1302,7 +1308,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;
@@ -1312,15 +1319,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++)
@@ -1337,7 +1347,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;
}
--
2.7.4
More information about the wine-patches
mailing list