From 26591d4f2264c3f6636598dc86d4e4bed528658e Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Thu, 2 May 2019 17:42:38 -0700 Subject: [PATCH] std.HashMap: add putAssumeCapacity fn --- std/hash_map.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/std/hash_map.zig b/std/hash_map.zig index 9d4c5318db..31750d1106 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -181,8 +181,13 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 /// Returns the kv pair that was already there. pub fn put(self: *Self, key: K, value: V) !?KV { - self.incrementModificationCount(); try self.autoCapacity(); + return putAssumeCapacity(self, key, value); + } + + pub fn putAssumeCapacity(self: *Self, key: K, value: V) ?KV { + assert(self.count() < self.entries.len); + self.incrementModificationCount(); const put_result = self.internalPut(key); put_result.new_entry.kv.value = value;