That way both representations are optimal in memory for their intended usecase. - `TagRef` is decodable from a buffer refers to it with all of its fields. That way round-trips are cheapest. - `Tag` does not allocate for hashes as there is a more compact representation: `git_hash::ObjectId`.
Showing the changes to git-object/src/commit/write.rs (1 of 6 files). Show all
Unified · Split
| @@ -23,6 +23,10 @@ impl crate::WriteTo for Commit { · 22 unmodified lines | |||
| 23 | out.write_all(&self.message) | 23 | out.write_all(&self.message) |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | fn kind(&self) -> Kind { | ||
| 27 | Kind::Commit | ||
| 28 | } | ||
| 29 | |||
| 26 | fn size(&self) -> usize { | 30 | fn size(&self) -> usize { |
| 27 | let hash_in_hex = self.tree.kind().len_in_hex(); | 31 | let hash_in_hex = self.tree.kind().len_in_hex(); |
| 28 | b"tree".len() + 1 /*space*/ + hash_in_hex + 1 /* nl */ | 32 | b"tree".len() + 1 /*space*/ + hash_in_hex + 1 /* nl */ |
| @@ -45,10 +49,6 @@ impl crate::WriteTo for Commit { · 16 unmodified lines | |||
| 45 | + 1 /* nl */ | 49 | + 1 /* nl */ |
| 46 | + self.message.len() | 50 | + self.message.len() |
| 47 | } | 51 | } |
| 48 | |||
| 49 | fn kind(&self) -> Kind { | ||
| 50 | Kind::Commit | ||
| 51 | } | ||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | impl<'a> crate::WriteTo for CommitRef<'a> { | 54 | impl<'a> crate::WriteTo for CommitRef<'a> { |
| @@ -70,6 +70,10 @@ impl<'a> crate::WriteTo for CommitRef<'a> { · 15 unmodified lines | |||
| 70 | out.write_all(self.message) | 70 | out.write_all(self.message) |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | fn kind(&self) -> Kind { | ||
| 74 | Kind::Commit | ||
| 75 | } | ||
| 76 | |||
| 73 | fn size(&self) -> usize { | 77 | fn size(&self) -> usize { |
| 74 | let hash_in_hex = self.tree().kind().len_in_hex(); | 78 | let hash_in_hex = self.tree().kind().len_in_hex(); |
| 75 | b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */ | 79 | b"tree".len() + 1 /* space */ + hash_in_hex + 1 /* nl */ |
| @@ -92,8 +96,4 @@ impl<'a> crate::WriteTo for CommitRef<'a> { · 16 unmodified lines | |||
| 92 | + 1 /* nl */ | 96 | + 1 /* nl */ |
| 93 | + self.message.len() | 97 | + self.message.len() |
| 94 | } | 98 | } |
| 95 | |||
| 96 | fn kind(&self) -> Kind { | ||
| 97 | Kind::Commit | ||
| 98 | } | ||
| 99 | } | 99 | } |