[haiku-commits] Change in haiku[master]: PicturePlayer: use BStackOrHeapArray

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 8 Jun 2020 09:22:22 +0000

From X512 <danger_mail@xxxxxxx>:

X512 has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2894 ;)


Change subject: PicturePlayer: use BStackOrHeapArray
......................................................................

PicturePlayer: use BStackOrHeapArray

Change-Id: I7908d8304276d14782bde5c2b8c089f3ca0138e2
---
M src/kits/interface/PicturePlayer.cpp
1 file changed, 7 insertions(+), 23 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/94/2894/1

diff --git a/src/kits/interface/PicturePlayer.cpp 
b/src/kits/interface/PicturePlayer.cpp
index bf2a2c9..322b19c 100644
--- a/src/kits/interface/PicturePlayer.cpp
+++ b/src/kits/interface/PicturePlayer.cpp
@@ -21,6 +21,7 @@
 #include <PictureProtocol.h>
 #include <Shape.h>

+#include <StackOrHeapArray.h>

 using BPrivate::PicturePlayer;

@@ -116,24 +117,15 @@
 {
        adapter_context* context = reinterpret_cast<adapter_context*>(_context);

-       // This is rather ugly but works for such a trivial class.
-       const size_t kMaxStackCount = 200;
-       char stackData[kMaxStackCount * sizeof(BPoint)];
-       BPoint* points = (BPoint*)stackData;
-       if (numPoints > kMaxStackCount) {
-               points = (BPoint*)malloc(numPoints * sizeof(BPoint));
-               if (points == NULL)
-                       return;
-       }
+       BStackOrHeapArray<BPoint, 200*sizeof(BPoint)> points(numPoints);
+       if (!points.IsValid())
+               return;

        memcpy((void*)points, _points, numPoints * sizeof(BPoint));

        ((void (*)(void*, int32, BPoint*, bool))
                context->function_table[fill ? 14 : 13])(context->user_data, 
numPoints,
                        points, isClosed);
-
-       if (numPoints > kMaxStackCount)
-               free(points);
 }


@@ -196,22 +188,14 @@
        adapter_context* context = reinterpret_cast<adapter_context*>(_context);

        // This is rather ugly but works for such a trivial class.
-       const size_t kMaxStackCount = 100;
-       char stackData[kMaxStackCount * sizeof(BRect)];
-       BRect* rects = (BRect*)stackData;
-       if (numRects > kMaxStackCount) {
-               rects = (BRect*)malloc(numRects * sizeof(BRect));
-               if (rects == NULL)
-                       return;
-       }
+       BStackOrHeapArray<BRect, 100*sizeof(BRect)> rects(numRects);
+       if (!rects.IsValid())
+               return;

        memcpy((void*)rects, _rects, numRects * sizeof(BRect));

        ((void (*)(void*, BRect*, uint32))context->function_table[20])(
                context->user_data, rects, numRects);
-
-       if (numRects > kMaxStackCount)
-               free(rects);
 }



--
To view, visit https://review.haiku-os.org/c/haiku/+/2894
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I7908d8304276d14782bde5c2b8c089f3ca0138e2
Gerrit-Change-Number: 2894
Gerrit-PatchSet: 1
Gerrit-Owner: X512 <danger_mail@xxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: PicturePlayer: use BStackOrHeapArray - Gerrit