Skip to content

Commit fb9731e

Browse files
committed
Remove unnecessary function
1 parent e870822 commit fb9731e

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

library/std/src/path.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a> Prefix<'a> {
193193
fn len(&self) -> usize {
194194
use self::Prefix::*;
195195
fn os_str_len(s: &OsStr) -> usize {
196-
os_str_as_u8_slice(s).len()
196+
s.bytes().len()
197197
}
198198
match *self {
199199
Verbatim(x) => 4 + os_str_len(x),
@@ -299,19 +299,17 @@ where
299299
}
300300
}
301301

302-
// See note at the top of this module to understand why these are used:
303-
//
304-
// These casts are safe as OsStr is internally a wrapper around [u8] on all
305-
// platforms.
306-
//
307-
// Note that currently this relies on the special knowledge that libstd has;
308-
// these types are single-element structs but are not marked repr(transparent)
309-
// or repr(C) which would make these casts allowable outside std.
310-
fn os_str_as_u8_slice(s: &OsStr) -> &[u8] {
311-
unsafe { &*(s as *const OsStr as *const [u8]) }
312-
}
313302
unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr {
314-
// SAFETY: see the comment of `os_str_as_u8_slice`
303+
// SAFETY: See note at the top of this module to understand why this and
304+
// `OsStr::bytes` are used:
305+
//
306+
// This casts are safe as OsStr is internally a wrapper around [u8] on all
307+
// platforms.
308+
//
309+
// Note that currently this relies on the special knowledge that libstd has;
310+
// these types are single-element structs but are not marked
311+
// repr(transparent) or repr(C) which would make these casts not allowable
312+
// outside std.
315313
unsafe { &*(s as *const [u8] as *const OsStr) }
316314
}
317315

@@ -332,15 +330,15 @@ fn has_physical_root(s: &[u8], prefix: Option<Prefix<'_>>) -> bool {
332330

333331
// basic workhorse for splitting stem and extension
334332
fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) {
335-
if os_str_as_u8_slice(file) == b".." {
333+
if file.bytes() == b".." {
336334
return (Some(file), None);
337335
}
338336

339337
// The unsafety here stems from converting between &OsStr and &[u8]
340338
// and back. This is safe to do because (1) we only look at ASCII
341339
// contents of the encoding and (2) new &OsStr values are produced
342340
// only from ASCII-bounded slices of existing &OsStr values.
343-
let mut iter = os_str_as_u8_slice(file).rsplitn(2, |b| *b == b'.');
341+
let mut iter = file.bytes().rsplitn(2, |b| *b == b'.');
344342
let after = iter.next();
345343
let before = iter.next();
346344
if before == Some(b"") {
@@ -351,7 +349,7 @@ fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) {
351349
}
352350

353351
fn split_file_at_dot(file: &OsStr) -> (&OsStr, Option<&OsStr>) {
354-
let slice = os_str_as_u8_slice(file);
352+
let slice = file.bytes();
355353
if slice == b".." {
356354
return (file, None);
357355
}
@@ -1445,17 +1443,17 @@ impl PathBuf {
14451443
fn _set_extension(&mut self, extension: &OsStr) -> bool {
14461444
let file_stem = match self.file_stem() {
14471445
None => return false,
1448-
Some(f) => os_str_as_u8_slice(f),
1446+
Some(f) => f.bytes(),
14491447
};
14501448

14511449
// truncate until right after the file stem
14521450
let end_file_stem = file_stem[file_stem.len()..].as_ptr().addr();
1453-
let start = os_str_as_u8_slice(&self.inner).as_ptr().addr();
1451+
let start = self.inner.bytes().as_ptr().addr();
14541452
let v = self.as_mut_vec();
14551453
v.truncate(end_file_stem.wrapping_sub(start));
14561454

14571455
// add the new extension, if any
1458-
let new = os_str_as_u8_slice(extension);
1456+
let new = extension.bytes();
14591457
if !new.is_empty() {
14601458
v.reserve_exact(new.len() + 1);
14611459
v.push(b'.');
@@ -1948,7 +1946,7 @@ impl Path {
19481946
}
19491947
// The following (private!) function reveals the byte encoding used for OsStr.
19501948
fn as_u8_slice(&self) -> &[u8] {
1951-
os_str_as_u8_slice(&self.inner)
1949+
self.inner.bytes()
19521950
}
19531951

19541952
/// Directly wraps a string slice as a `Path` slice.

0 commit comments

Comments
 (0)