mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
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:
committed by
Fabian Boehm
parent
0874dd6a96
commit
dceefcdaba
@@ -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]))
|
||||
|
||||
Reference in New Issue
Block a user