about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/raw_vec.rs16
-rw-r--r--src/liballoc/vec.rs2
2 files changed, 17 insertions, 1 deletions
diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index 7ef0a27fc72..dc8ad9ee061 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -68,6 +68,16 @@ impl<T, A: Alloc> RawVec<T, A> {
         }
     }
 
+    /// Like `empty` but parametrized over the choice of allocator for the returned `RawVec`.
+    pub const fn empty_in(a: A) -> Self {
+        // Unique::empty() doubles as "unallocated" and "zero-sized allocation"
+        RawVec {
+            ptr: Unique::empty(),
+            cap: 0,
+            a,
+        }
+    }
+
     /// Like `with_capacity` but parameterized over the choice of
     /// allocator for the returned RawVec.
     #[inline]
@@ -124,6 +134,12 @@ impl<T> RawVec<T, Global> {
         Self::new_in(Global)
     }
 
+    /// Create a `RawVec` with capcity 0 (on the system heap), regardless of `T`, without
+    /// allocating.
+    pub fn empty() -> Self {
+        Self::empty_in(Global)
+    }
+
     /// Creates a RawVec (on the system heap) with exactly the
     /// capacity and alignment requirements for a `[T; cap]`. This is
     /// equivalent to calling RawVec::new when `cap` is 0 or T is
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index b184404c15b..757606607bb 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -324,7 +324,7 @@ impl<T> Vec<T> {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn new() -> Vec<T> {
         Vec {
-            buf: RawVec::new(),
+            buf: RawVec::empty(),
             len: 0,
         }
     }