Skip to content

Commit d69c8a1

Browse files
authored
Merge pull request #3 from oschwald/greg/perf-improvements
Small performance improvements
2 parents 4325b64 + d9a3c37 commit d69c8a1

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/decoder.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,12 @@ 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));
195+
194196
for (0..map_len) |_| {
195197
const key = try self.decodeValue(allocator, Key);
196198
const value = try self.decodeValue(allocator, Value);
197-
try map.put(key, value);
199+
map.putAssumeCapacity(key, value);
198200
}
199201

200202
return map;

src/geoip2.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22

3-
pub const Names = std.hash_map.StringHashMap([]const u8);
3+
pub const Names = std.StringArrayHashMap([]const u8);
44

55
/// Country represents a record in the GeoIP2-Country database, for example,
66
/// https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoIP2-Country-Test.json.

src/geolite2.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const std = @import("std");
22

3-
pub const Names = std.hash_map.StringHashMap([]const u8);
3+
pub const Names = std.StringArrayHashMap([]const u8);
44

55
/// Country represents a record in the GeoLite2-Country database, for example,
66
/// https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-Country-Test.json.

src/reader.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub const Metadata = struct {
2020
binary_format_minor_version: u16 = 0,
2121
build_epoch: u64 = 0,
2222
database_type: []const u8 = "",
23-
description: ?std.hash_map.StringHashMap([]const u8) = null,
23+
description: ?std.StringArrayHashMap([]const u8) = null,
2424
ip_version: u16 = 0,
2525
languages: ?std.ArrayList([]const u8) = null,
2626
node_count: u32 = 0,

0 commit comments

Comments
 (0)