diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-03-01 15:21:49 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-03-01 15:21:49 +0100 |
| commit | 04be85c636f4e19e59915d8c0f12d9c9e97113b4 (patch) | |
| tree | 987d7f672f1c483a4e20ae49c2a7afb14e4c35ad /src/Fl_String.cxx | |
| parent | fc5f0c13f2f08aaeb80c6c123ed55467183ecf9f (diff) | |
Improved Fl_String capacity increments
Diffstat (limited to 'src/Fl_String.cxx')
| -rw-r--r-- | src/Fl_String.cxx | 9 |
1 files changed, 6 insertions, 3 deletions
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_); |
