Skip to content

Commit a2d5350

Browse files
committed
refactor(component): reduce allocations in ComponentPart::encode()
1 parent 6606aa7 commit a2d5350

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/dist/component/components.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,16 @@ impl ComponentPart {
198198
const PATH_SEP_MAIN: &str = std::path::MAIN_SEPARATOR_STR;
199199

200200
pub(crate) fn encode(&self) -> String {
201+
let mut buf = self.kind.to_string();
202+
buf.push(':');
201203
// Lossy conversion is safe here because we assume that `path` comes from
202204
// `ComponentPart::decode()`, i.e. from calling `Path::from()` on a `&str`.
203205
let mut path = self.path.to_string_lossy();
204206
if Self::PATH_SEP_MAIN != Self::PATH_SEP_MANIFEST {
205207
path = Cow::Owned(path.replace(Self::PATH_SEP_MAIN, Self::PATH_SEP_MANIFEST));
206208
};
207-
format!("{}:{path}", self.kind)
209+
buf.push_str(&path);
210+
buf
208211
}
209212

210213
pub(crate) fn decode(line: &str) -> Option<Self> {

0 commit comments

Comments
 (0)