mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
Micro-optimize sourcemaps (#17757)
Co-authored-by: chloe caruso <git@paperclover.net>
This commit is contained in:
@@ -43,10 +43,23 @@ pub fn owns(this: *const MutableString, items: []const u8) bool {
|
||||
return bun.isSliceInBuffer(items, this.list.items.ptr[0..this.list.capacity]);
|
||||
}
|
||||
|
||||
pub fn growIfNeeded(self: *MutableString, amount: usize) Allocator.Error!void {
|
||||
pub inline fn growIfNeeded(self: *MutableString, amount: usize) Allocator.Error!void {
|
||||
try self.list.ensureUnusedCapacity(self.allocator, amount);
|
||||
}
|
||||
|
||||
pub fn writableNBytesAssumeCapacity(self: *MutableString, amount: usize) []u8 {
|
||||
bun.assert(self.list.items.len + amount <= self.list.capacity);
|
||||
self.list.items.len += amount;
|
||||
return self.list.items[self.list.items.len - amount ..];
|
||||
}
|
||||
|
||||
/// Increases the length of the buffer by `amount` bytes, expanding the capacity if necessary.
|
||||
/// Returns a pointer to the end of the list - `amount` bytes.
|
||||
pub fn writableNBytes(self: *MutableString, amount: usize) Allocator.Error![]u8 {
|
||||
try self.growIfNeeded(amount);
|
||||
return self.writableNBytesAssumeCapacity(amount);
|
||||
}
|
||||
|
||||
pub fn write(self: *MutableString, bytes: anytype) Allocator.Error!usize {
|
||||
bun.debugAssert(bytes.len == 0 or !bun.isSliceInBuffer(bytes, self.list.allocatedSlice()));
|
||||
try self.list.appendSlice(self.allocator, bytes);
|
||||
|
||||
Reference in New Issue
Block a user