Skip to content

Commit

Permalink
Rollup merge of rust-lang#40410 - clarcharr:os_string_shrink_to_fit, …
Browse files Browse the repository at this point in the history
…r=alexcrichton

OsString::shrink_to_fit.

Considering how the other capacity-related methods are there, I found it odd that this one wasn't included.

Will create a tracking issue once I get an OK on this.
  • Loading branch information
Ariel Ben-Yehuda committed Mar 10, 2017
2 parents 8da64f8 + 83814fd commit 308650a
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 308650a

Please sign in to comment.