Skip to content

Commit 9bb8683

Browse files
committed
Set array capacity
1 parent d69c8a1 commit 9bb8683

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/decoder.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub const Decoder = struct {
191191
const Value = std.meta.FieldType(DecodedType.KV, .value);
192192
var map = DecodedType.init(allocator);
193193
const map_len = field.size;
194-
try map.ensureTotalCapacity(@intCast(map_len));
194+
try map.ensureTotalCapacity(map_len);
195195

196196
for (0..map_len) |_| {
197197
const key = try self.decodeValue(allocator, Key);
@@ -209,8 +209,9 @@ pub const Decoder = struct {
209209
}
210210

211211
const Value = std.meta.Child(DecodedType.Slice);
212-
var array = std.ArrayList(Value).init(allocator);
213212
const array_len = field.size;
213+
var array = try std.ArrayList(Value).initCapacity(allocator, array_len);
214+
214215
for (0..array_len) |_| {
215216
const value = try self.decodeValue(allocator, Value);
216217
try array.append(value);

src/maxminddb.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test {
1717
}
1818

1919
fn expectEqualMaps(
20-
map: std.hash_map.StringHashMap([]const u8),
20+
map: std.StringArrayHashMap([]const u8),
2121
keys: []const []const u8,
2222
values: []const []const u8,
2323
) !void {

0 commit comments

Comments
 (0)