Commit 17abb7ef7f
MCRusher <Modernwarfare3Minecraft64@gmail.com>
2019-11-24 05:49:55
Adds initCapacity() to buffer and arraylist
array_list.zig:
- adds ArrayList.initCapacity(*Allocator,usize) to allow preallocation of a block at initialization to reduce future allocations.
- adds a test for ArrayList.initCapacity() that ensures ArrayList.len() is unchanged and that at least the requested amount is allocated for.
buffer.zig:
- adds Buffer.initCapacity(*Allocator,usize), based off of ArrayList.initCapacity(), to preallocate a buffer before use.
note: contrary to Buffer.initSize(0) and then Buffer.list.ensureCapacity(200) (the presumed current method), this only allocates once instead of twice.
- adds Buffer.capacity to check usable allocated space, not including the null byte.
note: returns 0 when Buffer has only a null byte or when initNull() was used before without resize()/replaceContents().
- adds a test "Buffer.initCapacity" which ensures that Buffer.append()'s with [added size <= Buffer.capacity()-Buffer.len()] do not cause a reallocation to occur.
- adds a test "Buffer.initSize" which ensures that Buffer.initSize() behaves as expected, also combined with Buffer.append().
- adds a doc comment to Buffer.initSize() that makes its function and distinction from Buffer.initCapacity() clearer.
Changed files (0)
(no files)