[haiku-commits] haiku: hrev54303 - in src: servers/app kits/interface

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 8 Jun 2020 10:19:22 -0400 (EDT)

hrev54303 adds 2 changesets to branch 'master'
old head: c4bc68830480bfca8d55b9dd9ab5acd983ac5071
new head: 1d22b1ae639388ceb82dcb3b23d476295795a7fb
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=1d22b1ae6393+%5Ec4bc68830480

----------------------------------------------------------------------------

9692db62e7cf: app_server: use BStackOrHeapArray
  
  Change-Id: Ieb335d51923bf28b0e4f830535f74dede42933a3
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2893
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

1d22b1ae6393: PicturePlayer: use BStackOrHeapArray
  
  Change-Id: I7908d8304276d14782bde5c2b8c089f3ca0138e2
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/2894
  Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

                                              [ X512 <danger_mail@xxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 31 insertions(+), 91 deletions(-)
src/kits/interface/PicturePlayer.cpp | 31 ++++---------
src/servers/app/ServerPicture.cpp    | 14 ++----
src/servers/app/ServerWindow.cpp     | 77 +++++++++-----------------------

############################################################################

Commit:      9692db62e7cf9b090dc216bf03ff9e49157b924d
URL:         https://git.haiku-os.org/haiku/commit/?id=9692db62e7cf
Author:      X512 <danger_mail@xxxxxxx>
Date:        Mon Jun  8 08:34:14 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Mon Jun  8 14:19:18 2020 UTC

app_server: use BStackOrHeapArray

Change-Id: Ieb335d51923bf28b0e4f830535f74dede42933a3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2893
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/servers/app/ServerPicture.cpp 
b/src/servers/app/ServerPicture.cpp
index 3e26ff5f1b..4bd6537655 100644
--- a/src/servers/app/ServerPicture.cpp
+++ b/src/servers/app/ServerPicture.cpp
@@ -355,14 +355,9 @@ draw_polygon(void* _canvas, size_t numPoints, const BPoint 
viewPoints[],
        if (numPoints == 0)
                return;
 
-       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> points(numPoints);
+       if (!points.IsValid())
+               return;
 
        canvas->PenToScreenTransform().Apply(points, viewPoints, numPoints);
 
@@ -371,9 +366,6 @@ draw_polygon(void* _canvas, size_t numPoints, const BPoint 
viewPoints[],
 
        canvas->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame,
                fill, isClosed && numPoints > 2);
-
-       if (numPoints > kMaxStackCount)
-               free(points);
 }
 
 
diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp
index 16901589c1..f236c10969 100644
--- a/src/servers/app/ServerWindow.cpp
+++ b/src/servers/app/ServerWindow.cpp
@@ -47,6 +47,7 @@
 #include <PortLink.h>
 #include <ShapePrivate.h>
 #include <ServerProtocolStructs.h>
+#include <StackOrHeapArray.h>
 #include <ViewPrivate.h>
 #include <WindowInfo.h>
 #include <WindowPrivate.h>
@@ -3078,15 +3079,11 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
                                break;
                        }
 
-                       const ssize_t kMaxStackStringSize = 4096;
-                       char stackString[kMaxStackStringSize];
-                       char* string = stackString;
-                       if (info.stringLength >= kMaxStackStringSize) {
-                               // NOTE: Careful, the + 1 is for termination!
-                               string = (char*)malloc((info.stringLength + 1 + 
63) / 64 * 64);
-                               if (string == NULL)
-                                       break;
-                       }
+                       // NOTE: Careful, the + 1 is for termination!
+                       BStackOrHeapArray<char, 4096> string(
+                               (info.stringLength + 1 + 63) / 64 * 64);
+                       if (!string.IsValid())
+                               break;
 
                        escapement_delta* delta = NULL;
                        if (code == AS_DRAW_STRING_WITH_DELTA) {
@@ -3094,11 +3091,9 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
                                delta = &info.delta;
                        }
 
-                       if (link.Read(string, info.stringLength) != B_OK) {
-                               if (string != stackString)
-                                       free(string);
+                       if (link.Read(string, info.stringLength) != B_OK)
                                break;
-                       }
+
                        // Terminate the string, if nothing else, it's important
                        // for the DTRACE call below...
                        string[info.stringLength] = '\0';
@@ -3113,8 +3108,6 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
                        
fCurrentView->ScreenToPenTransform().Apply(&penLocation);
                        
fCurrentView->CurrentState()->SetPenLocation(penLocation);
 
-                       if (string != stackString)
-                               free(string);
                        break;
                }
                case AS_DRAW_STRING_WITH_OFFSETS:
@@ -3127,27 +3120,12 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
                        if (link.Read<int32>(&glyphCount) != B_OK || glyphCount 
<= 0)
                                break;
 
-                       const ssize_t kMaxStackStringSize = 512;
-                       char stackString[kMaxStackStringSize];
-                       char* string = stackString;
-                       BPoint stackLocations[kMaxStackStringSize];
-                       BPoint* locations = stackLocations;
-                       MemoryDeleter stringDeleter;
-                       MemoryDeleter locationsDeleter;
-                       if (stringLength >= kMaxStackStringSize) {
-                               // NOTE: Careful, the + 1 is for termination!
-                               string = (char*)malloc((stringLength + 1 + 63) 
/ 64 * 64);
-                               if (string == NULL)
-                                       break;
-                               stringDeleter.SetTo(string);
-                       }
-                       if (glyphCount > kMaxStackStringSize) {
-                               locations = (BPoint*)malloc(
-                                       ((glyphCount * sizeof(BPoint)) + 63) / 
64 * 64);
-                               if (locations == NULL)
-                                       break;
-                               locationsDeleter.SetTo(locations);
-                       }
+                       // NOTE: Careful, the + 1 is for termination!
+                       BStackOrHeapArray<char, 512> string(
+                               (stringLength + 1 + 63) / 64 * 64);
+                       BStackOrHeapArray<BPoint, 512> locations(glyphCount);
+                       if (!string.IsValid() || !locations.IsValid())
+                               break;
 
                        if (link.Read(string, stringLength) != B_OK)
                                break;
@@ -3647,27 +3625,12 @@ ServerWindow::_DispatchPictureMessage(int32 code, 
BPrivate::LinkReceiver& link)
                        if (link.Read<int32>(&glyphCount) != B_OK || glyphCount 
<= 0)
                                break;
 
-                       const ssize_t kMaxStackStringSize = 512;
-                       char stackString[kMaxStackStringSize];
-                       char* string = stackString;
-                       BPoint stackLocations[kMaxStackStringSize];
-                       BPoint* locations = stackLocations;
-                       MemoryDeleter stringDeleter;
-                       MemoryDeleter locationsDeleter;
-                       if (stringLength >= kMaxStackStringSize) {
-                               // NOTE: Careful, the + 1 is for termination!
-                               string = (char*)malloc((stringLength + 1 + 63) 
/ 64 * 64);
-                               if (string == NULL)
-                                       break;
-                               stringDeleter.SetTo(string);
-                       }
-                       if (glyphCount > kMaxStackStringSize) {
-                               locations = (BPoint*)malloc(
-                                       ((glyphCount * sizeof(BPoint)) + 63) / 
64 * 64);
-                               if (locations == NULL)
-                                       break;
-                               locationsDeleter.SetTo(locations);
-                       }
+                       // NOTE: Careful, the + 1 is for termination!
+                       BStackOrHeapArray<char, 512> string(
+                               (stringLength + 1 + 63) / 64 * 64);
+                       BStackOrHeapArray<BPoint, 512> locations(glyphCount);
+                       if (!string.IsValid() || !locations.IsValid())
+                               break;
 
                        if (link.Read(string, stringLength) != B_OK)
                                break;

############################################################################

Revision:    hrev54303
Commit:      1d22b1ae639388ceb82dcb3b23d476295795a7fb
URL:         https://git.haiku-os.org/haiku/commit/?id=1d22b1ae6393
Author:      X512 <danger_mail@xxxxxxx>
Date:        Mon Jun  8 09:13:00 2020 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Mon Jun  8 14:19:18 2020 UTC

PicturePlayer: use BStackOrHeapArray

Change-Id: I7908d8304276d14782bde5c2b8c089f3ca0138e2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2894
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>

----------------------------------------------------------------------------

diff --git a/src/kits/interface/PicturePlayer.cpp 
b/src/kits/interface/PicturePlayer.cpp
index bf2a2c9788..0e893f89a7 100644
--- a/src/kits/interface/PicturePlayer.cpp
+++ b/src/kits/interface/PicturePlayer.cpp
@@ -21,6 +21,8 @@
 #include <PictureProtocol.h>
 #include <Shape.h>
 
+#include <StackOrHeapArray.h>
+
 
 using BPrivate::PicturePlayer;
 
@@ -116,24 +118,15 @@ draw_polygon(void* _context, size_t numPoints, const 
BPoint _points[],
 {
        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> 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 +189,14 @@ set_clipping_rects(void* _context, size_t numRects, const 
BRect _rects[])
        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> 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);
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev54303 - in src: servers/app kits/interface - waddlesplash