mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
### What does this PR do? ### How did you verify your code works? --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
26 lines
724 B
Zig
26 lines
724 B
Zig
const IndexStringMap = @This();
|
|
|
|
pub const Index = bun.ast.Index;
|
|
|
|
map: std.AutoArrayHashMapUnmanaged(Index.Int, []const u8) = .{},
|
|
|
|
pub fn deinit(self: *IndexStringMap, allocator: std.mem.Allocator) void {
|
|
for (self.map.values()) |value| {
|
|
allocator.free(value);
|
|
}
|
|
self.map.deinit(allocator);
|
|
}
|
|
|
|
pub fn get(self: *const IndexStringMap, index: Index.Int) ?[]const u8 {
|
|
return self.map.get(index);
|
|
}
|
|
|
|
pub fn put(self: *IndexStringMap, allocator: std.mem.Allocator, index: Index.Int, value: []const u8) !void {
|
|
const duped = try allocator.dupe(u8, value);
|
|
errdefer allocator.free(duped);
|
|
try self.map.put(allocator, index, duped);
|
|
}
|
|
|
|
const bun = @import("bun");
|
|
const std = @import("std");
|