Skip to content

Commit 7913b5d

Browse files
committed
Feedback: static
1 parent d625aed commit 7913b5d

File tree

1 file changed

+2
-44
lines changed
  • turbopack/crates/turbo-tasks-fs/src

1 file changed

+2
-44
lines changed

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

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111

1212
use RopeElem::{Local, Shared};
1313
use anyhow::{Context, Result};
14-
use bytes::{Buf, Bytes};
14+
use bytes::Buf;
1515
use futures::Stream;
1616
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1717
use serde_bytes::ByteBuf;
@@ -81,12 +81,6 @@ enum Uncommitted {
8181
#[default]
8282
None,
8383

84-
/// Stores our attempt to push static lifetime bytes into the rope. If we
85-
/// build the Rope or concatenate another Rope, we can commit a static
86-
/// Bytes reference and save memory. If not, we'll concatenate this into
87-
/// writable bytes to be committed later.
88-
Static(&'static [u8]),
89-
9084
/// Mutable bytes collection where non-static/non-shared bytes are written.
9185
/// This builds until the next time a static or shared bytes is
9286
/// appended, in which case we split the buffer and commit. Finishing
@@ -173,13 +167,6 @@ impl RopeBuilder {
173167
return;
174168
}
175169

176-
// If the string is smaller than the cost of a Bytes reference (4 usizes), then
177-
// it's more efficient to own the bytes in a new buffer. We may be able to reuse
178-
// that buffer when more bytes are pushed.
179-
if bytes.len() < mem::size_of::<Bytes>() {
180-
return self.uncommitted.push_static_bytes(bytes);
181-
}
182-
183170
// We may have pending bytes from a prior push.
184171
self.finish();
185172

@@ -283,7 +270,6 @@ impl Uncommitted {
283270
fn len(&self) -> usize {
284271
match self {
285272
Uncommitted::None => 0,
286-
Uncommitted::Static(s) => s.len(),
287273
Uncommitted::Owned(v) => v.len(),
288274
}
289275
}
@@ -294,39 +280,15 @@ impl Uncommitted {
294280
debug_assert!(!bytes.is_empty(), "must not push empty uncommitted bytes");
295281
match self {
296282
Self::None => *self = Self::Owned(bytes.to_vec()),
297-
Self::Static(s) => {
298-
// If we'd previously pushed static bytes, we instead concatenate those bytes
299-
// with the new bytes in an attempt to use less memory rather than committing 2
300-
// Bytes references (2 * 4 usizes).
301-
let v = [s, bytes].concat();
302-
*self = Self::Owned(v);
303-
}
304283
Self::Owned(v) => v.extend(bytes),
305284
}
306285
}
307286

308-
/// Pushes static lifetime bytes, but only if the current representation is
309-
/// None. Else, it coverts to an Owned.
310-
fn push_static_bytes(&mut self, bytes: &'static [u8]) {
311-
debug_assert!(!bytes.is_empty(), "must not push empty uncommitted bytes");
312-
match self {
313-
// If we've not already pushed static bytes, we attempt to store the bytes for later. If
314-
// we push owned bytes or another static bytes, then this attempt will fail and we'll
315-
// instead concatenate into a single owned Bytes. But if we don't push anything (build
316-
// the Rope), or concatenate another Rope (we can't join our bytes with the InnerRope of
317-
// another Rope), we'll be able to commit a static Bytes reference and save overall
318-
// memory (a small static Bytes reference is better than a small owned Bytes reference).
319-
Self::None => *self = Self::Static(bytes),
320-
_ => self.push_bytes(bytes),
321-
}
322-
}
323-
324287
/// Converts the current uncommitted bytes into a `Cow<'static, [u8]>`, resetting our
325288
/// representation to None.
326289
fn finish(&mut self) -> Option<Cow<'static, [u8]>> {
327290
match mem::take(self) {
328291
Self::None => None,
329-
Self::Static(s) => Some(Cow::Borrowed(s)),
330292
Self::Owned(mut v) => {
331293
v.shrink_to_fit();
332294
Some(v.into())
@@ -339,11 +301,7 @@ impl fmt::Debug for Uncommitted {
339301
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
340302
match self {
341303
Uncommitted::None => f.write_str("None"),
342-
Uncommitted::Static(s) => f.debug_tuple("Static").field(&Cow::Borrowed(s)).finish(),
343-
Uncommitted::Owned(v) => f
344-
.debug_tuple("Owned")
345-
.field(&Bytes::from(v.clone()))
346-
.finish(),
304+
Uncommitted::Owned(v) => f.debug_tuple("Owned").field(&v).finish(),
347305
}
348306
}
349307
}

0 commit comments

Comments
 (0)