| ... | ... | @@ -273,8 +273,6 @@ pub const Node = struct { |
| 273 | 273 | /// The root node of the trie. |
| 274 | 274 | root: ?*Node = null, |
| 275 | 275 | |
| 276 | | allocator: *Allocator, |
| 277 | | |
| 278 | 276 | /// If you want to access nodes ordered in DFS fashion, |
| 279 | 277 | /// you should call `finalize` first since the nodes |
| 280 | 278 | /// in this container are not guaranteed to not be stale |
| ... | ... | @@ -294,10 +292,6 @@ node_count: usize = 0, |
| 294 | 292 | |
| 295 | 293 | trie_dirty: bool = true, |
| 296 | 294 | |
| 297 | | pub fn init(allocator: *Allocator) Trie { |
| 298 | | return .{ .allocator = allocator }; |
| 299 | | } |
| 300 | | |
| 301 | 295 | /// Export symbol that is to be placed in the trie. |
| 302 | 296 | pub const ExportSymbol = struct { |
| 303 | 297 | /// Name of the symbol. |
| ... | ... | @@ -314,9 +308,9 @@ pub const ExportSymbol = struct { |
| 314 | 308 | /// Insert a symbol into the trie, updating the prefixes in the process. |
| 315 | 309 | /// This operation may change the layout of the trie by splicing edges in |
| 316 | 310 | /// certain circumstances. |
| 317 | | pub fn put(self: *Trie, symbol: ExportSymbol) !void { |
| 318 | | try self.createRoot(); |
| 319 | | const node = try self.root.?.put(self.allocator, symbol.name); |
| 311 | pub fn put(self: *Trie, allocator: *Allocator, symbol: ExportSymbol) !void { |
| 312 | try self.createRoot(allocator); |
| 313 | const node = try self.root.?.put(allocator, symbol.name); |
| 320 | 314 | node.terminal_info = .{ |
| 321 | 315 | .vmaddr_offset = symbol.vmaddr_offset, |
| 322 | 316 | .export_flags = symbol.export_flags, |
| ... | ... | @@ -328,13 +322,13 @@ pub fn put(self: *Trie, symbol: ExportSymbol) !void { |
| 328 | 322 | /// This step performs multiple passes through the trie ensuring |
| 329 | 323 | /// there are no gaps after every `Node` is ULEB128 encoded. |
| 330 | 324 | /// Call this method before trying to `write` the trie to a byte stream. |
| 331 | | pub fn finalize(self: *Trie) !void { |
| 325 | pub fn finalize(self: *Trie, allocator: *Allocator) !void { |
| 332 | 326 | if (!self.trie_dirty) return; |
| 333 | 327 | |
| 334 | 328 | self.ordered_nodes.shrinkRetainingCapacity(0); |
| 335 | | try self.ordered_nodes.ensureCapacity(self.allocator, self.node_count); |
| 329 | try self.ordered_nodes.ensureCapacity(allocator, self.node_count); |
| 336 | 330 | |
| 337 | | var fifo = std.fifo.LinearFifo(*Node, .Dynamic).init(self.allocator); |
| 331 | var fifo = std.fifo.LinearFifo(*Node, .Dynamic).init(allocator); |
| 338 | 332 | defer fifo.deinit(); |
| 339 | 333 | |
| 340 | 334 | try fifo.writeItem(self.root.?); |
| ... | ... | @@ -383,17 +377,17 @@ pub fn write(self: Trie, writer: anytype) !u64 { |
| 383 | 377 | return counting_writer.bytes_written; |
| 384 | 378 | } |
| 385 | 379 | |
| 386 | | pub fn deinit(self: *Trie) void { |
| 380 | pub fn deinit(self: *Trie, allocator: *Allocator) void { |
| 387 | 381 | if (self.root) |root| { |
| 388 | | root.deinit(self.allocator); |
| 389 | | self.allocator.destroy(root); |
| 382 | root.deinit(allocator); |
| 383 | allocator.destroy(root); |
| 390 | 384 | } |
| 391 | | self.ordered_nodes.deinit(self.allocator); |
| 385 | self.ordered_nodes.deinit(allocator); |
| 392 | 386 | } |
| 393 | 387 | |
| 394 | | fn createRoot(self: *Trie) !void { |
| 388 | fn createRoot(self: *Trie, allocator: *Allocator) !void { |
| 395 | 389 | if (self.root == null) { |
| 396 | | const root = try self.allocator.create(Node); |
| 390 | const root = try allocator.create(Node); |
| 397 | 391 | root.* = .{ .base = self }; |
| 398 | 392 | self.root = root; |
| 399 | 393 | self.node_count += 1; |