Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how
CowData
manages its allocations
- Use an explicit type for the data prefix to enable easier changes. - Explicitly store the capacity instead of using the next power of two. - If resizing to a significantly larger size (more 2x the current capacity), assume that the caller has just resized to their final size and don't allocate any excess capacity. - Trim the capacity less aggressively to fix edge cases when repeatedly adding and removing elements causing extreme performance issues. - Do not rely on overflow checked operations to determine the maximum size, to avoid crashes with some compilers when using too large sizes. - On 64-bit system increase the the maximum size to 0x7ffffff0, generally by a factor of the size of the elements. - On 32-bit system the maximum size remains limited by the size of the address space / memory, but in some cases it may still be possible to allocate larger arrays compared to before. - Add a minimum capacity to remove some unnecessary reallocation for small arrays. - Remove a few unnecessary potential copies when resizing, adding or removing elements.
- Loading branch information