From dd5285875e67f110871e290ca03edb91b6b70ef7 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 12 Jun 2020 23:41:49 -0700 Subject: [PATCH] clear clears --- zig-ecs/src/ecs/sparse_set.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zig-ecs/src/ecs/sparse_set.zig b/zig-ecs/src/ecs/sparse_set.zig index e5cfc9a..d0660b4 100644 --- a/zig-ecs/src/ecs/sparse_set.zig +++ b/zig-ecs/src/ecs/sparse_set.zig @@ -224,6 +224,14 @@ pub fn SparseSet(comptime SparseT: type) type { } pub fn clear(self: *Self) void { + self.sparse.expandToCapacity(); + for (self.sparse.items) |array, i| { + if (array) |arr| { + self.sparse.allocator.free(arr); + self.sparse.items[i] = null; + } + } + self.sparse.items.len = 0; self.dense.items.len = 0; }