Skip to content

Commit

Permalink
OsString::shrink_to_fit.
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Mar 10, 2017
1 parent ec87925 commit 83814fd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
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

0 comments on commit 83814fd

Please sign in to comment.