- extracted functions
- factorised extern "C" into a block containing all function prototypes instead of writing macros all over the place
- using intermediate buffers instead of writing directly to the output file
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.
Added Buffer.initCapcity() to buffer to allow preallocation of a block of memory to reduce future allocations. Uses the added ArrayList.initCapacity() function to achieve this.
Added Buffer.capacity() to track current usable allocation size, not counting null byte, and returning 0 if empty or created with Buffer.initNull()
Added a test for initCapacity() that shows that no further allocation is performed for an append of size smaller than or equal to capacity when initCapacity is used.
Added a test for initSize(), since it did not exist already.
Also added a comment to better explain the difference between initSize() and initCapacity()
note: forgot in the first commit but thanks to mikdusan for helping me brainstorm, through the process, and for drawing up a draft diff which I tweaked.
Added ArrayList.initCapcity() as a way to preallocate a block of memory to reduce future allocations.
Added a test "std.ArrayList.initCapacity" that ensures initCapacity adds no elements and increases capacity by at least the requested amount
this also deletes C string literals from the language, and then makes
the std lib changes and compiler changes necessary to get the behavior
tests and std lib tests passing again.