Skip to content

Commit

Permalink
windows platforms accounted for, should close rust-lang#126333
Browse files Browse the repository at this point in the history
  • Loading branch information
Borgerr committed Jun 24, 2024
1 parent 7525e9d commit 564cfc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 13 additions & 3 deletions library/std/src/sys/os_str/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,20 @@ impl Buf {
self.as_slice().into_rc()
}

/// Part of a hack to make PathBuf::push/pop more efficient.
/// More well behaving alternative to allowing outer types
/// full mutable access to the core `Vec`.
/// Provides plumbing to core `Vec::truncate`.
#[inline]
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
self.inner.as_mut_vec_for_path_buf()
pub(crate) fn truncate(&mut self, len: usize) {
self.inner.truncate(len);
}

/// More well behaving alternative to allowing outer types
/// full mutable access to the core `Vec`.
/// Provides plumbing to core `Vec::extend_from_slice`.
#[inline]
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
self.inner.extend_from_slice(other);
}
}

Expand Down
11 changes: 5 additions & 6 deletions library/std/src/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,12 @@ impl Wtf8Buf {
Wtf8Buf { bytes: bytes.into_vec(), is_known_utf8: false }
}

/// Part of a hack to make PathBuf::push/pop more efficient.
/// More well behaving alternative to allowing outer types
/// full mutable access to the core `Vec`.
/// Provides plumbing to core `Vec::extend_from_slice`.
#[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
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
self.bytes.extend_from_slice(other);
}
}

Expand Down

0 comments on commit 564cfc6

Please sign in to comment.