Skip to content

Commit d299d37

Browse files
CopilotByron
andcommitted
Clarify comment about Cow variant preservation for efficiency
Co-authored-by: Byron <[email protected]>
1 parent 005538f commit d299d37

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gix-config-value/src/path.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ impl<'a> From<Cow<'a, BStr>> for Path<'a> {
113113
fn from(value: Cow<'a, BStr>) -> Self {
114114
// Check if the value starts with ":(optional)" prefix
115115
if value.starts_with(OPTIONAL_PREFIX) {
116-
// Strip the prefix while preserving the Cow variant to avoid unnecessary allocations
116+
// Strip the prefix while preserving the Cow variant for efficiency:
117+
// - Borrowed data remains borrowed (no allocation)
118+
// - Owned data is modified in-place using drain (no extra allocation)
117119
let stripped = match value {
118120
Cow::Borrowed(b) => Cow::Borrowed(&b[OPTIONAL_PREFIX.len()..]),
119121
Cow::Owned(mut b) => {

0 commit comments

Comments
 (0)