From 6f6fa8b9546e0b1005732caa774c39944325a63f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 21 Oct 2021 23:08:57 +0200 Subject: Use SortedMap in HIR. --- compiler/rustc_data_structures/src/sorted_map.rs | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'compiler/rustc_data_structures') diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 20e2a3b9696..9efea1228ab 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -1,3 +1,4 @@ +use crate::stable_hasher::{HashStable, StableHasher}; use std::borrow::Borrow; use std::cmp::Ordering; use std::iter::FromIterator; @@ -16,17 +17,26 @@ pub use index_map::SortedIndexMultiMap; /// stores data in a more compact way. It also supports accessing contiguous /// ranges of elements as a slice, and slices of already sorted elements can be /// inserted efficiently. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, Encodable, Decodable)] -pub struct SortedMap { +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] +pub struct SortedMap { data: Vec<(K, V)>, } -impl SortedMap { +impl Default for SortedMap { + #[inline] + fn default() -> SortedMap { + SortedMap { data: Vec::new() } + } +} + +impl SortedMap { #[inline] - pub fn new() -> SortedMap { - SortedMap { data: vec![] } + pub const fn new() -> SortedMap { + SortedMap { data: Vec::new() } } +} +impl SortedMap { /// Construct a `SortedMap` from a presorted set of elements. This is faster /// than creating an empty map and then inserting the elements individually. /// @@ -281,5 +291,12 @@ impl FromIterator<(K, V)> for SortedMap { } } +impl, V: HashStable, CTX> HashStable for SortedMap { + #[inline] + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + self.data.hash_stable(ctx, hasher); + } +} + #[cfg(test)] mod tests; -- cgit 1.4.1-3-g733a5