From 86990636d466f720d01981714a1b8d317e2f2729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 6 Apr 2009 12:38:15 +0000 Subject: [PATCH] Avoid using the heap allocator for most string drawing when reading the command from the link. My benchmark measuring is inconclusive, the numbers are sometimes very different. At first sight, it looks like string drawing can be up to double as fast with this change, but sometimes, the numbers are about the same. Hm. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29965 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/ServerWindow.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 7bd1352d20..f51b298ed5 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -2788,9 +2788,15 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, if (link.Read(&info) != B_OK) break; - char* string = (char*)malloc(info.stringLength + 1); - if (string == NULL) - 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; + } escapement_delta* delta = NULL; if (code == AS_DRAW_STRING_WITH_DELTA) { @@ -2799,7 +2805,8 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, } if (link.Read(string, info.stringLength) != B_OK) { - free(string); + if (string != stackString) + free(string); break; } // Terminate the string, if nothing else, it's important @@ -2816,7 +2823,8 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code, fCurrentView->ConvertFromScreenForDrawing(&penLocation); fCurrentView->CurrentState()->SetPenLocation(penLocation); - free(string); + if (string != stackString) + free(string); break; }