@@ -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
@@ -1290,7 +1285,8 @@ impl PathBuf {
12901285
12911286 fn _push ( & mut self , path : & Path ) {
12921287 // in general, a separator is needed if the rightmost byte is not a separator
1293- let mut need_sep = self . as_mut_vec ( ) . last ( ) . map ( |c| !is_sep_byte ( * c) ) . unwrap_or ( false ) ;
1288+ let buf = self . inner . as_encoded_bytes ( ) ;
1289+ let mut need_sep = buf. last ( ) . map ( |c| !is_sep_byte ( * c) ) . unwrap_or ( false ) ;
12941290
12951291 // in the special case of `C:` on Windows, do *not* add a separator
12961292 let comps = self . components ( ) ;
@@ -1304,7 +1300,7 @@ impl PathBuf {
13041300
13051301 // absolute `path` replaces `self`
13061302 if path. is_absolute ( ) || path. prefix ( ) . is_some ( ) {
1307- self . as_mut_vec ( ) . truncate ( 0 ) ;
1303+ self . inner . truncate ( 0 ) ;
13081304
13091305 // verbatim paths need . and .. removed
13101306 } else if comps. prefix_verbatim ( ) && !path. inner . is_empty ( ) {
@@ -1349,7 +1345,7 @@ impl PathBuf {
13491345 // `path` has a root but no prefix, e.g., `\windows` (Windows only)
13501346 } else if path. has_root ( ) {
13511347 let prefix_len = self . components ( ) . prefix_remaining ( ) ;
1352- self . as_mut_vec ( ) . truncate ( prefix_len) ;
1348+ self . inner . truncate ( prefix_len) ;
13531349
13541350 // `path` is a pure relative path
13551351 } else if need_sep {
@@ -1382,7 +1378,7 @@ impl PathBuf {
13821378 pub fn pop ( & mut self ) -> bool {
13831379 match self . parent ( ) . map ( |p| p. as_u8_slice ( ) . len ( ) ) {
13841380 Some ( len) => {
1385- self . as_mut_vec ( ) . truncate ( len) ;
1381+ self . inner . truncate ( len) ;
13861382 true
13871383 }
13881384 None => false ,
@@ -1510,15 +1506,14 @@ impl PathBuf {
15101506 // truncate until right after the file stem
15111507 let end_file_stem = file_stem[ file_stem. len ( ) ..] . as_ptr ( ) . addr ( ) ;
15121508 let start = self . inner . as_encoded_bytes ( ) . as_ptr ( ) . addr ( ) ;
1513- let v = self . as_mut_vec ( ) ;
1514- v. truncate ( end_file_stem. wrapping_sub ( start) ) ;
1509+ self . inner . truncate ( end_file_stem. wrapping_sub ( start) ) ;
15151510
15161511 // add the new extension, if any
1517- let new = extension. as_encoded_bytes ( ) ;
1512+ let new = extension;
15181513 if !new. is_empty ( ) {
1519- v . reserve_exact ( new. len ( ) + 1 ) ;
1520- v . push ( b'.' ) ;
1521- v . extend_from_slice ( new) ;
1514+ self . inner . reserve_exact ( new. len ( ) + 1 ) ;
1515+ self . inner . push ( OsStr :: new ( "." ) ) ;
1516+ self . inner . push ( new) ;
15221517 }
15231518
15241519 true
@@ -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 }
0 commit comments