@@ -11,7 +11,7 @@ use std::{
11
11
12
12
use RopeElem :: { Local , Shared } ;
13
13
use anyhow:: { Context , Result } ;
14
- use bytes:: { Buf , Bytes } ;
14
+ use bytes:: Buf ;
15
15
use futures:: Stream ;
16
16
use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
17
17
use serde_bytes:: ByteBuf ;
@@ -81,12 +81,6 @@ enum Uncommitted {
81
81
#[ default]
82
82
None ,
83
83
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
-
90
84
/// Mutable bytes collection where non-static/non-shared bytes are written.
91
85
/// This builds until the next time a static or shared bytes is
92
86
/// appended, in which case we split the buffer and commit. Finishing
@@ -173,13 +167,6 @@ impl RopeBuilder {
173
167
return ;
174
168
}
175
169
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
-
183
170
// We may have pending bytes from a prior push.
184
171
self . finish ( ) ;
185
172
@@ -283,7 +270,6 @@ impl Uncommitted {
283
270
fn len ( & self ) -> usize {
284
271
match self {
285
272
Uncommitted :: None => 0 ,
286
- Uncommitted :: Static ( s) => s. len ( ) ,
287
273
Uncommitted :: Owned ( v) => v. len ( ) ,
288
274
}
289
275
}
@@ -294,39 +280,15 @@ impl Uncommitted {
294
280
debug_assert ! ( !bytes. is_empty( ) , "must not push empty uncommitted bytes" ) ;
295
281
match self {
296
282
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
- }
304
283
Self :: Owned ( v) => v. extend ( bytes) ,
305
284
}
306
285
}
307
286
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
-
324
287
/// Converts the current uncommitted bytes into a `Cow<'static, [u8]>`, resetting our
325
288
/// representation to None.
326
289
fn finish ( & mut self ) -> Option < Cow < ' static , [ u8 ] > > {
327
290
match mem:: take ( self ) {
328
291
Self :: None => None ,
329
- Self :: Static ( s) => Some ( Cow :: Borrowed ( s) ) ,
330
292
Self :: Owned ( mut v) => {
331
293
v. shrink_to_fit ( ) ;
332
294
Some ( v. into ( ) )
@@ -339,11 +301,7 @@ impl fmt::Debug for Uncommitted {
339
301
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
340
302
match self {
341
303
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 ( ) ,
347
305
}
348
306
}
349
307
}
0 commit comments