Skip to content

Commit

Permalink
rust-lang#126333 literal removal of PathBuf::as_mut_vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Borgerr committed Jun 20, 2024
1 parent 4333551 commit 60d4777
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 34 deletions.
6 changes: 0 additions & 6 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,6 @@ impl OsString {
pub fn leak<'a>(self) -> &'a mut OsStr {
OsStr::from_inner_mut(self.inner.leak())
}

/// Part of a hack to make PathBuf::push/pop more efficient.
#[inline]
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
self.inner.as_mut_vec_for_path_buf()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
17 changes: 10 additions & 7 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@ impl<'a> Components<'a> {
/// how much of the prefix is left from the point of view of iteration?
#[inline]
fn prefix_remaining(&self) -> usize {
if self.front == State::Prefix { self.prefix_len() } else { 0 }
if self.front == State::Prefix {
self.prefix_len()
} else {
0
}
}

// Given the iteration so far, how much of the pre-State::Body path is left?
Expand All @@ -674,7 +678,11 @@ impl<'a> Components<'a> {

#[inline]
fn is_sep_byte(&self, b: u8) -> bool {
if self.prefix_verbatim() { is_verbatim_sep(b) } else { is_sep_byte(b) }
if self.prefix_verbatim() {
is_verbatim_sep(b)
} else {
is_sep_byte(b)
}
}

/// Extracts a slice corresponding to the portion of the path remaining for iteration.
Expand Down Expand Up @@ -1163,11 +1171,6 @@ pub struct PathBuf {
}

impl PathBuf {
#[inline]
fn as_mut_vec(&mut self) -> &mut Vec<u8> {
self.inner.as_mut_vec_for_path_buf()
}

/// Allocates an empty `PathBuf`.
///
/// # Examples
Expand Down
6 changes: 0 additions & 6 deletions library/std/src/sys/os_str/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ impl Buf {
pub fn into_rc(&self) -> Rc<Slice> {
self.as_slice().into_rc()
}

/// Part of a hack to make PathBuf::push/pop more efficient.
#[inline]
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
&mut self.inner
}
}

impl Slice {
Expand Down
6 changes: 0 additions & 6 deletions library/std/src/sys/os_str/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ impl Buf {
pub fn into_rc(&self) -> Rc<Slice> {
self.as_slice().into_rc()
}

/// Part of a hack to make PathBuf::push/pop more efficient.
#[inline]
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
self.inner.as_mut_vec_for_path_buf()
}
}

impl Slice {
Expand Down
9 changes: 0 additions & 9 deletions library/std/src/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,6 @@ impl Wtf8Buf {
let bytes: Box<[u8]> = unsafe { mem::transmute(boxed) };
Wtf8Buf { bytes: bytes.into_vec(), is_known_utf8: false }
}

/// Part of a hack to make PathBuf::push/pop more efficient.
#[inline]
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
// FIXME: this function should not even exist, as it implies violating Wtf8Buf invariants
// For now, simply assume that is about to happen.
self.is_known_utf8 = false;
&mut self.bytes
}
}

/// Creates a new WTF-8 string from an iterator of code points.
Expand Down

0 comments on commit 60d4777

Please sign in to comment.