From 2430870a2194bb16e867bf2d15ea45827e6d4f7e Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Wed, 19 Dec 2018 02:43:58 +0100 Subject: [PATCH] Make `SortedMap::new` const, also faster `is_empty`. --- src/librustc_data_structures/lib.rs | 2 ++ src/librustc_data_structures/sorted_map.rs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 8e0ecb70c6896..4187d7721c137 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -30,6 +30,8 @@ #![feature(allow_internal_unstable)] #![feature(vec_resize_with)] #![feature(hash_raw_entry)] +#![feature(const_fn)] +#![feature(const_vec_new)] #![cfg_attr(unix, feature(libc))] #![cfg_attr(test, feature(test))] diff --git a/src/librustc_data_structures/sorted_map.rs b/src/librustc_data_structures/sorted_map.rs index 3bd3d11660797..edd7e9c3d7bd0 100644 --- a/src/librustc_data_structures/sorted_map.rs +++ b/src/librustc_data_structures/sorted_map.rs @@ -30,9 +30,9 @@ pub struct SortedMap { impl SortedMap { #[inline] - pub fn new() -> SortedMap { + pub const fn new() -> SortedMap { SortedMap { - data: vec![] + data: Vec::new() } } @@ -144,7 +144,7 @@ impl SortedMap { #[inline] pub fn is_empty(&self) -> bool { - self.len() == 0 + self.data.is_empty() } #[inline]