Skip to content

Commit 4187d0e

Browse files
Justus2308mlugg
authored andcommitted
MemoryPool: add unmanaged variants and make them the default
1 parent 2508036 commit 4187d0e

File tree

3 files changed

+281
-113
lines changed

3 files changed

+281
-113
lines changed

lib/compiler/resinator/source_mapping.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ pub const SourceMappings = struct {
723723
/// The default assumes that the first filename added is the root file.
724724
/// The value should be set to the correct offset if that assumption does not hold.
725725
root_filename_offset: u32 = 0,
726-
source_node_pool: std.heap.MemoryPool(Sources.Node) = std.heap.MemoryPool(Sources.Node).init(std.heap.page_allocator),
726+
source_node_pool: std.heap.MemoryPool(Sources.Node) = .empty,
727727
end_line: usize = 0,
728728

729729
const sourceCompare = struct {
@@ -742,7 +742,7 @@ pub const SourceMappings = struct {
742742

743743
pub fn deinit(self: *SourceMappings, allocator: Allocator) void {
744744
self.files.deinit(allocator);
745-
self.source_node_pool.deinit();
745+
self.source_node_pool.deinit(std.heap.page_allocator);
746746
}
747747

748748
/// Find the node that 'contains' the `line`, i.e. the node's start_line is
@@ -823,7 +823,7 @@ pub const SourceMappings = struct {
823823
.filename_offset = filename_offset,
824824
};
825825
var entry = self.sources.getEntryFor(key);
826-
var new_node = try self.source_node_pool.create();
826+
var new_node = try self.source_node_pool.create(std.heap.page_allocator);
827827
new_node.key = key;
828828
entry.set(new_node);
829829
}
@@ -869,7 +869,7 @@ pub const SourceMappings = struct {
869869
.filename_offset = node.key.filename_offset,
870870
};
871871
var entry = self.sources.getEntryFor(key);
872-
var new_node = try self.source_node_pool.create();
872+
var new_node = try self.source_node_pool.create(std.heap.page_allocator);
873873
new_node.key = key;
874874
entry.set(new_node);
875875
node = new_node;

lib/std/heap.zig

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ pub const GeneralPurposeAllocatorConfig = DebugAllocatorConfig;
2525
/// Deprecated; to be removed after 0.14.0 is tagged.
2626
pub const GeneralPurposeAllocator = DebugAllocator;
2727

28-
const memory_pool = @import("heap/memory_pool.zig");
29-
pub const MemoryPool = memory_pool.MemoryPool;
30-
pub const MemoryPoolAligned = memory_pool.MemoryPoolAligned;
31-
pub const MemoryPoolExtra = memory_pool.MemoryPoolExtra;
28+
/// A memory pool that can allocate objects of a single type very quickly.
29+
/// Use this when you need to allocate a lot of objects of the same type,
30+
/// because it outperforms general purpose allocators.
31+
/// Functions that potentially allocate memory accept an `Allocator` parameter.
32+
pub fn MemoryPool(comptime Item: type) type {
33+
return memory_pool.Extra(Item, .{ .alignment = null });
34+
}
35+
pub const memory_pool = @import("heap/memory_pool.zig");
36+
37+
/// Deprecated; use `memory_pool.Aligned`.
38+
pub const MemoryPoolAligned = memory_pool.Aligned;
39+
/// Deprecated; use `memory_pool.Extra`.
40+
pub const MemoryPoolExtra = memory_pool.Extra;
41+
/// Deprecated; use `memory_pool.Options`.
3242
pub const MemoryPoolOptions = memory_pool.Options;
3343

3444
/// TODO Utilize this on Windows.

0 commit comments

Comments
 (0)