Skip to content

Commit faaace5

Browse files
committed
shrink vec before converting to Rope
1 parent 4bfc429 commit faaace5

File tree

1 file changed

+17
-1
lines changed
  • turbopack/crates/turbo-tasks-fs/src

1 file changed

+17
-1
lines changed

turbopack/crates/turbo-tasks-fs/src/rope.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,24 @@ impl Rope {
118118
}
119119
}
120120

121+
impl From<Vec<u8>> for Rope {
122+
fn from(mut bytes: Vec<u8>) -> Self {
123+
bytes.shrink_to_fit();
124+
let bytes: Bytes = bytes.into();
125+
// We can't have an InnerRope which contains an empty Local section.
126+
if bytes.is_empty() {
127+
Default::default()
128+
} else {
129+
Rope {
130+
length: bytes.len(),
131+
data: InnerRope(Arc::from([Local(bytes)])),
132+
}
133+
}
134+
}
135+
}
136+
121137
impl<T: Into<Bytes>> From<T> for Rope {
122-
fn from(bytes: T) -> Self {
138+
default fn from(bytes: T) -> Self {
123139
let bytes = bytes.into();
124140
// We can't have an InnerRope which contains an empty Local section.
125141
if bytes.is_empty() {

0 commit comments

Comments
 (0)