Add an appenln method to output_stream_t

This is an alternative to the very common pattern of

```rust
streams.err.append(output);
streams.err.append1('\n');
```

Which has negative performance implications, see https://github.com/fish-shell/fish-shell/pull/9229

It takes `Into<WString>` to hopefully avoid allocating anew when the argument is
a WString with leftover capacity
This commit is contained in:
Henrik Hørlück Berg
2023-08-13 23:14:40 +02:00
committed by Fabian Boehm
parent 0874dd6a96
commit dceefcdaba

View File

@@ -114,6 +114,12 @@ pub fn append<Str: AsRef<wstr>>(&mut self, s: Str) -> bool {
self.ffi().append(&s.as_ref().into_cpp())
}
/// Append a &wstr or WString with a newline
pub fn appendln(&mut self, s: impl Into<WString>) -> bool {
let s = s.into() + L!("\n");
self.ffi().append(&s.into_cpp())
}
/// Append a char.
pub fn append1(&mut self, c: char) -> bool {
self.append(wstr::from_char_slice(&[c]))