about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-03-10 16:51:46 -0600
committerAlex Crichton <alex@alexcrichton.com>2017-03-10 20:05:06 -0800
commitf4b4e097a6dcc5ffac6f3b34c91423708014c553 (patch)
tree105064d6510e014756352035f3e95ad0b8925ecf /src
parentdcf41821b88bc9c54aaa621f7e744405a33e2238 (diff)
parent83814fd8ab30e2744d2fb17bdcf5b59840673863 (diff)
downloadrust-f4b4e097a6dcc5ffac6f3b34c91423708014c553.tar.gz
rust-f4b4e097a6dcc5ffac6f3b34c91423708014c553.zip
Rollup merge of #40410 - clarcharr:os_string_shrink_to_fit, 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.
Diffstat (limited to 'src')
-rw-r--r--src/libstd/ffi/os_str.rs6
-rw-r--r--src/libstd/sys/redox/os_str.rs5
-rw-r--r--src/libstd/sys/unix/os_str.rs5
-rw-r--r--src/libstd/sys/windows/os_str.rs4
-rw-r--r--src/libstd/sys_common/wtf8.rs5
5 files changed, 25 insertions, 0 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index 7b8bf42e0a7..41bdd9c51d4 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -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> {
diff --git a/src/libstd/sys/redox/os_str.rs b/src/libstd/sys/redox/os_str.rs
index 0f967863899..474d59eed83 100644
--- a/src/libstd/sys/redox/os_str.rs
+++ b/src/libstd/sys/redox/os_str.rs
@@ -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) }
     }
diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs
index 938bcfc6d16..c27599ec020 100644
--- a/src/libstd/sys/unix/os_str.rs
+++ b/src/libstd/sys/unix/os_str.rs
@@ -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) }
     }
diff --git a/src/libstd/sys/windows/os_str.rs b/src/libstd/sys/windows/os_str.rs
index 04e45dcf549..b02b06e1ef2 100644
--- a/src/libstd/sys/windows/os_str.rs
+++ b/src/libstd/sys/windows/os_str.rs
@@ -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()) }
diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs
index 1d61181a4ee..b486d4ffda3 100644
--- a/src/libstd/sys_common/wtf8.rs
+++ b/src/libstd/sys_common/wtf8.rs
@@ -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 {