This re-implementation removed unnecessary API call to GdipGetPathPoints and avoids allocating memory unnecessarily.
It is also quite likely that this API doesn't ever return OutOfMemory errors.
Signed-off-by: David Kahurani k.kahurani@gmail.com
From: David Kahurani k.kahurani@gmail.com
This re-implementation removed unnecessary API call to GdipGetPathPoints and avoids allocating memory unnecessarily. Ontop of that, it is quite likely that this API doesn't ever return OutOfMemory errors.
Signed-off-by: David Kahurani k.kahurani@gmail.com --- dlls/gdiplus/graphicspath.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/dlls/gdiplus/graphicspath.c b/dlls/gdiplus/graphicspath.c index 24c2888cfe8..050ff46ef6b 100644 --- a/dlls/gdiplus/graphicspath.c +++ b/dlls/gdiplus/graphicspath.c @@ -1501,8 +1501,6 @@ GpStatus WINGDIPAPI GdipGetPathPoints(GpPath *path, GpPointF* points, INT count)
GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count) { - GpStatus ret; - GpPointF *ptf; INT i;
TRACE("(%p, %p, %d)\n", path, points, count); @@ -1510,18 +1508,15 @@ GpStatus WINGDIPAPI GdipGetPathPointsI(GpPath *path, GpPoint* points, INT count) if(count <= 0) return InvalidParameter;
- ptf = malloc(sizeof(GpPointF) * count); - if(!ptf) return OutOfMemory; - - ret = GdipGetPathPoints(path,ptf,count); - if(ret == Ok) - for(i = 0;i < count;i++){ - points[i].X = gdip_round(ptf[i].X); - points[i].Y = gdip_round(ptf[i].Y); - }; - free(ptf); + if(count < path->pathdata.Count) + return InsufficientBuffer; + + for(i = 0;i < path->pathdata.Count ;i++){ + points[i].X = gdip_round(path->pathdata.Points[i].X); + points[i].Y = gdip_round(path->pathdata.Points[i].Y); + };
- return ret; + return Ok; }
GpStatus WINGDIPAPI GdipGetPathTypes(GpPath *path, BYTE* types, INT count)
Is there any indication that this matters for performance?
Good question.
Sorry to disappoint but there is no observable effect on performance.
```c void GetPathPointsSmallHeavy() { GraphicsPath path; int x, y, length, width; PointF *dataPoints; double time_taken; for (int i = 0; i < 10; i++) { x = rand() % 1920; y = rand() % 1080; length = rand() / 1920; width = rand() / 1080;path.AddRectangle(Rect(x, y, length, width)); } dataPoints = new PointF[10 * 4]; auto started = std::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000000; i++) { path.GetPathPoints(dataPoints, 10 * 4); } auto done =std::chrono::high_resolution_clock::now();std::cout<<std::chrono::duration_caststd::chrono::milliseconds(done - started).count()<< std::endl; delete [] dataPoints; } ```
The above snippet consistently yields 14 - 15ms on both master and this MR's branch.
This merge request was closed by Esme Povirk.
Then I don't think it's worth breaking the pattern of the I functions forwarding to the float ones.