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

OsString::shrink_to_fit. #40410

Merged
merged 1 commit into from
Mar 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ impl OsString {
self.inner.reserve_exact(additional)
}

/// Shrinks the capacity of the `OsString` to match its length.
#[unstable(feature = "osstring_shrink_to_fit", issue = "40421")]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}

/// Converts this `OsString` into a boxed `OsStr`.
#[unstable(feature = "into_boxed_os_str", issue = "0")]
pub fn into_boxed_os_str(self) -> Box<OsStr> {
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/sys/redox/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ impl Buf {
self.inner.reserve_exact(additional)
}

#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}

pub fn as_slice(&self) -> &Slice {
unsafe { mem::transmute(&*self.inner) }
}
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/sys/unix/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ impl Buf {
self.inner.reserve_exact(additional)
}

#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}

pub fn as_slice(&self) -> &Slice {
unsafe { mem::transmute(&*self.inner) }
}
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/windows/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl Buf {
self.inner.reserve_exact(additional)
}

pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}

#[inline]
pub fn into_box(self) -> Box<Slice> {
unsafe { mem::transmute(self.inner.into_box()) }
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ impl Wtf8Buf {
self.bytes.reserve_exact(additional)
}

#[inline]
pub fn shrink_to_fit(&mut self) {
self.bytes.shrink_to_fit()
}

/// Returns the number of bytes that this string buffer can hold without reallocating.
#[inline]
pub fn capacity(&self) -> usize {
Expand Down