From 17abb7ef7f75705c1195022076e95cdde6ab2243 Mon Sep 17 00:00:00 2001 From: MCRusher Date: Sat, 23 Nov 2019 23:49:55 -0500 Subject: [PATCH] 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.