@@ -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
@@ -1290,7 +1285,8 @@ impl PathBuf {
1290
1285
1291
1286
fn _push ( & mut self , path : & Path ) {
1292
1287
// 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 ) ;
1294
1290
1295
1291
// in the special case of `C:` on Windows, do *not* add a separator
1296
1292
let comps = self . components ( ) ;
@@ -1304,7 +1300,7 @@ impl PathBuf {
1304
1300
1305
1301
// absolute `path` replaces `self`
1306
1302
if path. is_absolute ( ) || path. prefix ( ) . is_some ( ) {
1307
- self . as_mut_vec ( ) . truncate ( 0 ) ;
1303
+ self . inner . truncate ( 0 ) ;
1308
1304
1309
1305
// verbatim paths need . and .. removed
1310
1306
} else if comps. prefix_verbatim ( ) && !path. inner . is_empty ( ) {
@@ -1349,7 +1345,7 @@ impl PathBuf {
1349
1345
// `path` has a root but no prefix, e.g., `\windows` (Windows only)
1350
1346
} else if path. has_root ( ) {
1351
1347
let prefix_len = self . components ( ) . prefix_remaining ( ) ;
1352
- self . as_mut_vec ( ) . truncate ( prefix_len) ;
1348
+ self . inner . truncate ( prefix_len) ;
1353
1349
1354
1350
// `path` is a pure relative path
1355
1351
} else if need_sep {
@@ -1382,7 +1378,7 @@ impl PathBuf {
1382
1378
pub fn pop ( & mut self ) -> bool {
1383
1379
match self . parent ( ) . map ( |p| p. as_u8_slice ( ) . len ( ) ) {
1384
1380
Some ( len) => {
1385
- self . as_mut_vec ( ) . truncate ( len) ;
1381
+ self . inner . truncate ( len) ;
1386
1382
true
1387
1383
}
1388
1384
None => false ,
@@ -1510,15 +1506,14 @@ impl PathBuf {
1510
1506
// truncate until right after the file stem
1511
1507
let end_file_stem = file_stem[ file_stem. len ( ) ..] . as_ptr ( ) . addr ( ) ;
1512
1508
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) ) ;
1515
1510
1516
1511
// add the new extension, if any
1517
- let new = extension. as_encoded_bytes ( ) ;
1512
+ let new = extension;
1518
1513
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) ;
1522
1517
}
1523
1518
1524
1519
true
@@ -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
}
0 commit comments