mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
Static allocator polymorphism (#22227)
* Define a generic allocator interface to enable static polymorphism for allocators (see `GenericAllocator` in `src/allocators.zig`). Note that `std.mem.Allocator` itself is considered a generic allocator. * Add utilities to `bun.allocators` for working with generic allocators. * Add a new namespace, `bun.memory`, with basic utilities for working with memory and objects (`create`, `destroy`, `initDefault`, `deinit`). * Add `bun.DefaultAllocator`, a zero-sized generic allocator type whose `allocator` method simply returns `bun.default_allocator`. * Implement the generic allocator interface in `AllocationScope` and `MimallocArena`. * Improve `bun.threading.GuardedValue` (now `bun.threading.Guarded`). * Improve `bun.safety.AllocPtr` (now `bun.safety.CheckedAllocator`). (For internal tracking: fixes STAB-1085, STAB-1086, STAB-1087, STAB-1088, STAB-1089, STAB-1090, STAB-1091)
This commit is contained in:
@@ -245,13 +245,13 @@ pub fn toOwnedSlice(self: *MutableString) []u8 {
|
||||
}
|
||||
|
||||
pub fn toDynamicOwned(self: *MutableString) DynamicOwned([]u8) {
|
||||
return .fromRawOwned(self.toOwnedSlice(), self.allocator);
|
||||
return .fromRawIn(self.toOwnedSlice(), self.allocator);
|
||||
}
|
||||
|
||||
/// `self.allocator` must be `bun.default_allocator`.
|
||||
pub fn toDefaultOwned(self: *MutableString) Owned([]u8) {
|
||||
bun.safety.alloc.assertEq(self.allocator, bun.default_allocator);
|
||||
return .fromRawOwned(self.toOwnedSlice());
|
||||
return .fromRaw(self.toOwnedSlice());
|
||||
}
|
||||
|
||||
pub fn slice(self: *MutableString) []u8 {
|
||||
|
||||
Reference in New Issue
Block a user