Commit c47978a 1 parent 5ff8fbb commit c47978a Copy full SHA for c47978a
File tree 5 files changed +25
-7
lines changed
5 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,12 @@ impl OsString {
532
532
let rw = Box :: into_raw ( self . inner . into_box ( ) ) as * mut OsStr ;
533
533
unsafe { Box :: from_raw ( rw) }
534
534
}
535
+
536
+ /// Part of a hack to make PathBuf::push/pop more efficient.
537
+ #[ inline]
538
+ pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
539
+ self . inner . as_mut_vec_for_path_buf ( )
540
+ }
535
541
}
536
542
537
543
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -1158,20 +1158,14 @@ impl FusedIterator for Ancestors<'_> {}
1158
1158
/// Which method works best depends on what kind of situation you're in.
1159
1159
#[ cfg_attr( not( test) , rustc_diagnostic_item = "PathBuf" ) ]
1160
1160
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1161
- // `PathBuf::as_mut_vec` current implementation relies
1162
- // on `PathBuf` being layout-compatible with `Vec<u8>`.
1163
- // However, `PathBuf` layout is considered an implementation detail and must not be relied upon. We
1164
- // want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
1165
- // `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
1166
- #[ cfg_attr( not( doc) , repr( transparent) ) ]
1167
1161
pub struct PathBuf {
1168
1162
inner : OsString ,
1169
1163
}
1170
1164
1171
1165
impl PathBuf {
1172
1166
#[ inline]
1173
1167
fn as_mut_vec ( & mut self ) -> & mut Vec < u8 > {
1174
- unsafe { & mut * ( self as * mut PathBuf as * mut Vec < u8 > ) }
1168
+ self . inner . as_mut_vec_for_path_buf ( )
1175
1169
}
1176
1170
1177
1171
/// Allocates an empty `PathBuf`.
Original file line number Diff line number Diff line change @@ -198,6 +198,12 @@ impl Buf {
198
198
pub fn into_rc ( & self ) -> Rc < Slice > {
199
199
self . as_slice ( ) . into_rc ( )
200
200
}
201
+
202
+ /// Part of a hack to make PathBuf::push/pop more efficient.
203
+ #[ inline]
204
+ pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
205
+ & mut self . inner
206
+ }
201
207
}
202
208
203
209
impl Slice {
Original file line number Diff line number Diff line change @@ -158,6 +158,12 @@ impl Buf {
158
158
pub fn into_rc ( & self ) -> Rc < Slice > {
159
159
self . as_slice ( ) . into_rc ( )
160
160
}
161
+
162
+ /// Part of a hack to make PathBuf::push/pop more efficient.
163
+ #[ inline]
164
+ pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
165
+ self . inner . as_mut_vec_for_path_buf ( )
166
+ }
161
167
}
162
168
163
169
impl Slice {
Original file line number Diff line number Diff line change @@ -468,6 +468,12 @@ impl Wtf8Buf {
468
468
let bytes: Box < [ u8 ] > = unsafe { mem:: transmute ( boxed) } ;
469
469
Wtf8Buf { bytes : bytes. into_vec ( ) , is_known_utf8 : false }
470
470
}
471
+
472
+ /// Part of a hack to make PathBuf::push/pop more efficient.
473
+ #[ inline]
474
+ pub ( crate ) fn as_mut_vec_for_path_buf ( & mut self ) -> & mut Vec < u8 > {
475
+ & mut self . bytes
476
+ }
471
477
}
472
478
473
479
/// Creates a new WTF-8 string from an iterator of code points.
You can’t perform that action at this time.
0 commit comments