To not reallocate to smaller buffers.
Previously, if a state buffer was needed and the existing one did not match the size and type exactly, the old buffer was freed and a new buffer was malloced. However, malloc can be slow and it is possible to reuse a buffer if the new one being asked for is smaller than the old one. Thus, change the semantics to use a previously allocated buffer if it is at least as big as needed. This might leave pools of data larger than what we need, but will reduce the overall number of malloc calls needed.
Showing with 45 additions and 24 deletions