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
This commit is contained in:
Stephan Aßmus 2009-04-06 12:38:15 +00:00
parent 64f22f3d0d
commit 86990636d4

View File

@ -2788,9 +2788,15 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
if (link.Read<ViewDrawStringInfo>(&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;
}