File tree 5 files changed +42
-27
lines changed
5 files changed +42
-27
lines changed Original file line number Diff line number Diff line change @@ -552,15 +552,20 @@ impl OsString {
552
552
OsStr :: from_inner_mut ( self . inner . leak ( ) )
553
553
}
554
554
555
- /// Part of a hack to make PathBuf::push/pop more efficient.
555
+ /// Provides plumbing to core `Vec::truncate`.
556
+ /// More well behaving alternative to allowing outer types
557
+ /// full mutable access to the core `Vec`.
556
558
#[ inline]
557
- pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
558
- self . inner . as_mut_vec_for_path_buf ( )
559
+ pub ( crate ) fn truncate ( & mut self , len : usize ) {
560
+ self . inner . truncate ( len ) ;
559
561
}
560
562
563
+ /// Provides plumbing to core `Vec::extend_from_slice`.
564
+ /// More well behaving alternative to allowing outer types
565
+ /// full mutable access to the core `Vec`.
561
566
#[ inline]
562
- pub ( crate ) fn truncate ( & mut self , len : usize ) {
563
- self . inner . truncate ( len ) ;
567
+ pub ( crate ) fn extend_from_slice ( & mut self , other : & [ u8 ] ) {
568
+ self . inner . extend_from_slice ( other ) ;
564
569
}
565
570
}
566
571
Original file line number Diff line number Diff line change @@ -1163,11 +1163,6 @@ pub struct PathBuf {
1163
1163
}
1164
1164
1165
1165
impl PathBuf {
1166
- #[ inline]
1167
- fn as_mut_vec ( & mut self ) -> & mut Vec < u8 > {
1168
- self . inner . as_mut_vec_for_path_buf ( )
1169
- }
1170
-
1171
1166
/// Allocates an empty `PathBuf`.
1172
1167
///
1173
1168
/// # Examples
@@ -2645,18 +2640,18 @@ impl Path {
2645
2640
None => {
2646
2641
// Enough capacity for the extension and the dot
2647
2642
let capacity = self_len + extension. len ( ) + 1 ;
2648
- let whole_path = self_bytes. iter ( ) ;
2643
+ let whole_path = self_bytes;
2649
2644
( capacity, whole_path)
2650
2645
}
2651
2646
Some ( previous_extension) => {
2652
2647
let capacity = self_len + extension. len ( ) - previous_extension. len ( ) ;
2653
- let path_till_dot = self_bytes[ ..self_len - previous_extension. len ( ) ] . iter ( ) ;
2648
+ let path_till_dot = & self_bytes[ ..self_len - previous_extension. len ( ) ] ;
2654
2649
( capacity, path_till_dot)
2655
2650
}
2656
2651
} ;
2657
2652
2658
2653
let mut new_path = PathBuf :: with_capacity ( new_capacity) ;
2659
- new_path. as_mut_vec ( ) . extend ( slice_to_copy) ;
2654
+ new_path. inner . extend_from_slice ( slice_to_copy) ;
2660
2655
new_path. set_extension ( extension) ;
2661
2656
new_path
2662
2657
}
Original file line number Diff line number Diff line change @@ -202,15 +202,20 @@ impl Buf {
202
202
self . as_slice ( ) . into_rc ( )
203
203
}
204
204
205
- /// Part of a hack to make PathBuf::push/pop more efficient.
205
+ /// Provides plumbing to core `Vec::truncate`.
206
+ /// More well behaving alternative to allowing outer types
207
+ /// full mutable access to the core `Vec`.
206
208
#[ inline]
207
- pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
208
- & mut self . inner
209
+ pub ( crate ) fn truncate ( & mut self , len : usize ) {
210
+ self . inner . truncate ( len ) ;
209
211
}
210
212
213
+ /// Provides plumbing to core `Vec::extend_from_slice`.
214
+ /// More well behaving alternative to allowing outer types
215
+ /// full mutable access to the core `Vec`.
211
216
#[ inline]
212
- pub ( crate ) fn truncate ( & mut self , len : usize ) {
213
- self . inner . truncate ( len ) ;
217
+ pub ( crate ) fn extend_from_slice ( & mut self , other : & [ u8 ] ) {
218
+ self . inner . extend_from_slice ( other ) ;
214
219
}
215
220
}
216
221
Original file line number Diff line number Diff line change @@ -165,10 +165,20 @@ impl Buf {
165
165
self . as_slice ( ) . into_rc ( )
166
166
}
167
167
168
- /// Part of a hack to make PathBuf::push/pop more efficient.
168
+ /// Provides plumbing to core `Vec::truncate`.
169
+ /// More well behaving alternative to allowing outer types
170
+ /// full mutable access to the core `Vec`.
169
171
#[ inline]
170
- pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
171
- self . inner . as_mut_vec_for_path_buf ( )
172
+ pub ( crate ) fn truncate ( & mut self , len : usize ) {
173
+ self . inner . truncate ( len) ;
174
+ }
175
+
176
+ /// Provides plumbing to core `Vec::extend_from_slice`.
177
+ /// More well behaving alternative to allowing outer types
178
+ /// full mutable access to the core `Vec`.
179
+ #[ inline]
180
+ pub ( crate ) fn extend_from_slice ( & mut self , other : & [ u8 ] ) {
181
+ self . inner . extend_from_slice ( other) ;
172
182
}
173
183
}
174
184
Original file line number Diff line number Diff line change @@ -474,13 +474,13 @@ impl Wtf8Buf {
474
474
Wtf8Buf { bytes : bytes. into_vec ( ) , is_known_utf8 : false }
475
475
}
476
476
477
- /// Part of a hack to make PathBuf::push/pop more efficient.
477
+ /// Provides plumbing to core `Vec::extend_from_slice`.
478
+ /// More well behaving alternative to allowing outer types
479
+ /// full mutable access to the core `Vec`.
478
480
#[ inline]
479
- pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
480
- // FIXME: this function should not even exist, as it implies violating Wtf8Buf invariants
481
- // For now, simply assume that is about to happen.
482
- self . is_known_utf8 = false ;
483
- & mut self . bytes
481
+ pub ( crate ) fn extend_from_slice ( & mut self , other : & [ u8 ] ) {
482
+ self . bytes . extend_from_slice ( other) ;
483
+ self . is_known_utf8 = self . is_known_utf8 || self . next_surrogate ( 0 ) . is_none ( ) ;
484
484
}
485
485
}
486
486
You can’t perform that action at this time.
0 commit comments