std.ChildProcess: improvements to collectOutputPosix
* read directly into the ArrayList buffers. * respect max_output_bytes * std.ArrayList: - make `allocatedSlice` public. - add `unusedCapacitySlice`. I removed the Windows implementation of this stuff; I am doing a partial merge of LemonBoy's patch with the understanding that a later patch can add the Windows implementation after it is vetted.
This commit is contained in:
@@ -337,11 +337,21 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
||||
return self.pop();
|
||||
}
|
||||
|
||||
// For a nicer API, `items.len` is the length, not the capacity.
|
||||
// This requires "unsafe" slicing.
|
||||
fn allocatedSlice(self: Self) Slice {
|
||||
/// Returns a slice of all the items plus the extra capacity, whose memory
|
||||
/// contents are undefined.
|
||||
pub fn allocatedSlice(self: Self) Slice {
|
||||
// For a nicer API, `items.len` is the length, not the capacity.
|
||||
// This requires "unsafe" slicing.
|
||||
return self.items.ptr[0..self.capacity];
|
||||
}
|
||||
|
||||
/// Returns a slice of only the extra capacity after items.
|
||||
/// This can be useful for writing directly into an `ArrayList`.
|
||||
/// Note that such an operation must be followed up with a direct
|
||||
/// modification of `self.items.len`.
|
||||
pub fn unusedCapacitySlice(self: Self) Slice {
|
||||
return self.allocatedSlice()[self.items.len..];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user