`EmptyValue` is already used by `header_field` and seems suitable for the same case here. Also swap `lines()` for `split_str()` this way there's no need to handle the terminal edge case. And "deoptimise" `Commit[Ref]::write_to`: `header_field_multi_line` should work fine for single values, it *might* be slightly less efficient but I assume it's a pretty rare case anyway and the simplicity is more valuable, as well as avoiding redundant work.
Showing the changes to git-object/src/commit/write.rs (1 of 2 files). Show all
Unified · Split
| @@ -1,7 +1,5 @@ | ||
| 1 | 1 | use std::io; |
| 2 | 2 | |
| 3 | −use bstr::ByteSlice; | |
| 4 | − | |
| 5 | 3 | use crate::{encode, encode::NL, Commit, CommitRef, Kind}; |
| 6 | 4 | |
| 7 | 5 | impl crate::WriteTo for Commit { |
| @@ -17,12 +15,7 @@ impl crate::WriteTo for Commit { · 9 unmodified lines | ||
| 17 | 15 | encode::header_field(b"encoding", encoding, &mut out)?; |
| 18 | 16 | } |
| 19 | 17 | for (name, value) in &self.extra_headers { |
| 20 | − let has_newline = value.find_byte(b'\n').is_some(); | |
| 21 | − if has_newline { | |
| 22 | − encode::header_field_multi_line(name, value, &mut out)?; | |
| 23 | − } else { | |
| 24 | − encode::trusted_header_field(name, value, &mut out)?; | |
| 25 | − } | |
| 18 | + encode::header_field_multi_line(name, value, &mut out)?; | |
| 26 | 19 | } |
| 27 | 20 | out.write_all(NL)?; |
| 28 | 21 | out.write_all(&self.message) |
| @@ -46,12 +39,7 @@ impl<'a> crate::WriteTo for CommitRef<'a> { · 17 unmodified lines | ||
| 46 | 39 | encode::header_field(b"encoding", encoding, &mut out)?; |
| 47 | 40 | } |
| 48 | 41 | for (name, value) in &self.extra_headers { |
| 49 | − let has_newline = value.find_byte(b'\n').is_some(); | |
| 50 | − if has_newline { | |
| 51 | − encode::header_field_multi_line(name, value, &mut out)?; | |
| 52 | − } else { | |
| 53 | − encode::trusted_header_field(name, value, &mut out)?; | |
| 54 | − } | |
| 42 | + encode::header_field_multi_line(name, value, &mut out)?; | |
| 55 | 43 | } |
| 56 | 44 | out.write_all(NL)?; |
| 57 | 45 | out.write_all(self.message) |