Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove internal PathBuf::as_mut_vec #126885

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
inner truncate methods for UEFI platforms
Borgerr committed Jun 25, 2024
commit b08cd69684e4b121399b3ea0f9ee6cc4a51cad07
5 changes: 5 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
@@ -557,6 +557,11 @@ impl OsString {
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
self.inner.as_mut_vec_for_path_buf()
}

#[inline]
pub(crate) fn truncate(&mut self, len: usize) {
self.inner.truncate(len);
}
}

#[stable(feature = "rust1", since = "1.0.0")]
6 changes: 3 additions & 3 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
@@ -1305,7 +1305,7 @@ impl PathBuf {

// absolute `path` replaces `self`
if path.is_absolute() || path.prefix().is_some() {
self.as_mut_vec().truncate(0);
self.inner.truncate(0);

// verbatim paths need . and .. removed
} else if comps.prefix_verbatim() && !path.inner.is_empty() {
@@ -1350,7 +1350,7 @@ impl PathBuf {
// `path` has a root but no prefix, e.g., `\windows` (Windows only)
} else if path.has_root() {
let prefix_len = self.components().prefix_remaining();
self.as_mut_vec().truncate(prefix_len);
self.inner.truncate(prefix_len);

// `path` is a pure relative path
} else if need_sep {
@@ -1383,7 +1383,7 @@ impl PathBuf {
pub fn pop(&mut self) -> bool {
match self.parent().map(|p| p.as_u8_slice().len()) {
Some(len) => {
self.as_mut_vec().truncate(len);
self.inner.truncate(len);
true
}
None => false,
5 changes: 5 additions & 0 deletions library/std/src/sys/os_str/bytes.rs
Original file line number Diff line number Diff line change
@@ -207,6 +207,11 @@ impl Buf {
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {
&mut self.inner
}

#[inline]
pub(crate) fn truncate(&mut self, len: usize) {
self.inner.truncate(len);
}
}

impl Slice {