From 29c11327c703f59ad39d5840768864106b7c27b7 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Tue, 21 Mar 2023 22:17:15 +0100 Subject: [PATCH] Use `SmallVec` in bitsets This doesn't increase their size and means that we don't have to heap allocate for small sets. --- compiler/rustc_index/src/bit_set.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index cbf169afb18c1..eba5b3ed882a1 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -1,5 +1,6 @@ use crate::vec::{Idx, IndexVec}; use arrayvec::ArrayVec; +use smallvec::{smallvec, SmallVec}; use std::fmt; use std::iter; use std::marker::PhantomData; @@ -111,7 +112,7 @@ macro_rules! bit_relations_inherent_impls { #[derive(Eq, PartialEq, Hash, Decodable, Encodable)] pub struct BitSet { domain_size: usize, - words: Vec, + words: SmallVec<[Word; 2]>, marker: PhantomData, } @@ -127,14 +128,15 @@ impl BitSet { #[inline] pub fn new_empty(domain_size: usize) -> BitSet { let num_words = num_words(domain_size); - BitSet { domain_size, words: vec![0; num_words], marker: PhantomData } + BitSet { domain_size, words: smallvec![0; num_words], marker: PhantomData } } /// Creates a new, filled bitset with a given `domain_size`. #[inline] pub fn new_filled(domain_size: usize) -> BitSet { let num_words = num_words(domain_size); - let mut result = BitSet { domain_size, words: vec![!0; num_words], marker: PhantomData }; + let mut result = + BitSet { domain_size, words: smallvec![!0; num_words], marker: PhantomData }; result.clear_excess_bits(); result } @@ -1571,7 +1573,7 @@ impl From> for GrowableBitSet { pub struct BitMatrix { num_rows: usize, num_columns: usize, - words: Vec, + words: SmallVec<[Word; 2]>, marker: PhantomData<(R, C)>, } @@ -1584,7 +1586,7 @@ impl BitMatrix { BitMatrix { num_rows, num_columns, - words: vec![0; num_rows * words_per_row], + words: smallvec![0; num_rows * words_per_row], marker: PhantomData, } }