From 04be85c636f4e19e59915d8c0f12d9c9e97113b4 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 1 Mar 2023 15:21:49 +0100 Subject: Improved Fl_String capacity increments --- src/Fl_String.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Fl_String.cxx b/src/Fl_String.cxx index 222e34583..fc21c3652 100644 --- a/src/Fl_String.cxx +++ b/src/Fl_String.cxx @@ -63,10 +63,13 @@ void Fl_String::grow_(int n) { // round n up so we can grow in chunks if (alloc_size_ <= 24) { // allocate at least 24 bytes alloc_size_ = 24; - } else if (alloc_size_ < 1024) { - alloc_size_ = (alloc_size_+128) & ~127; // allocate in 128 byte chunks + } else if (alloc_size_ < 1024 + 8) { + alloc_size_ = ((alloc_size_+128-8) & ~127) + 8; // allocate in 128 byte chunks } else { - alloc_size_ = (alloc_size_+2048) & ~2047; // allocate in 2k chunks + alloc_size_ = ((alloc_size_+2048-8) & ~2047) + 8; // allocate in 2k chunks + // adding 8 keeps the buffer 64-bit aligned while generating a space for + // the trailing NUL without jumping to the next chunk size for common + // allocations like 1024 or 2048 (FL_PATH_MAX). } // allocate now char *new_buffer = (char*)::malloc(alloc_size_); -- cgit v1.2.3