File tree Expand file tree Collapse file tree 5 files changed +42
-27
lines changed Expand file tree Collapse file tree 5 files changed +42
-27
lines changed Original file line number Diff line number Diff line change @@ -552,15 +552,20 @@ impl OsString {
552552 OsStr :: from_inner_mut ( self . inner . leak ( ) )
553553 }
554554
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`.
556558 #[ 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 ) ;
559561 }
560562
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`.
561566 #[ 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 ) ;
564569 }
565570}
566571
Original file line number Diff line number Diff line change @@ -1163,11 +1163,6 @@ pub struct PathBuf {
11631163}
11641164
11651165impl PathBuf {
1166- #[ inline]
1167- fn as_mut_vec ( & mut self ) -> & mut Vec < u8 > {
1168- self . inner . as_mut_vec_for_path_buf ( )
1169- }
1170-
11711166 /// Allocates an empty `PathBuf`.
11721167 ///
11731168 /// # Examples
@@ -2645,18 +2640,18 @@ impl Path {
26452640 None => {
26462641 // Enough capacity for the extension and the dot
26472642 let capacity = self_len + extension. len ( ) + 1 ;
2648- let whole_path = self_bytes. iter ( ) ;
2643+ let whole_path = self_bytes;
26492644 ( capacity, whole_path)
26502645 }
26512646 Some ( previous_extension) => {
26522647 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 ( ) ] ;
26542649 ( capacity, path_till_dot)
26552650 }
26562651 } ;
26572652
26582653 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) ;
26602655 new_path. set_extension ( extension) ;
26612656 new_path
26622657 }
Original file line number Diff line number Diff line change @@ -202,15 +202,20 @@ impl Buf {
202202 self . as_slice ( ) . into_rc ( )
203203 }
204204
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`.
206208 #[ 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 ) ;
209211 }
210212
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`.
211216 #[ 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 ) ;
214219 }
215220}
216221
Original file line number Diff line number Diff line change @@ -165,10 +165,20 @@ impl Buf {
165165 self . as_slice ( ) . into_rc ( )
166166 }
167167
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`.
169171 #[ 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) ;
172182 }
173183}
174184
Original file line number Diff line number Diff line change @@ -474,13 +474,13 @@ impl Wtf8Buf {
474474 Wtf8Buf { bytes : bytes. into_vec ( ) , is_known_utf8 : false }
475475 }
476476
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`.
478480 #[ 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 ( ) ;
484484 }
485485}
486486
You can’t perform that action at this time.
0 commit comments