@@ -70,12 +70,15 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
7070use util:: nodemap:: FnvHashMap ;
7171use util:: num:: ToPrimitive ;
7272
73+ use rustc_data_structures:: bitset:: { U8BitSet , BitSet , BitSetIter } ;
74+
7375use arena:: TypedArena ;
7476use std:: borrow:: { Borrow , Cow } ;
7577use std:: cell:: { Cell , RefCell , Ref } ;
7678use std:: cmp;
7779use std:: fmt;
7880use std:: hash:: { Hash , SipHasher , Hasher } ;
81+ use std:: mem;
7982use std:: ops;
8083use std:: rc:: Rc ;
8184use std:: vec:: IntoIter ;
@@ -2059,28 +2062,28 @@ pub struct ExistentialBounds<'tcx> {
20592062
20602063#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
20612064pub struct BuiltinBounds {
2062- bits : u8
2065+ bit_set : U8BitSet
20632066}
20642067
20652068impl BuiltinBounds {
20662069 pub fn empty ( ) -> BuiltinBounds {
2067- BuiltinBounds { bits : 0 }
2070+ BuiltinBounds { bit_set : BitSet :: empty ( ) }
20682071 }
20692072
20702073 pub fn insert ( & mut self , bound : BuiltinBound ) {
2071- self . bits |= 1 << ( bound as u8 ) ;
2074+ self . bit_set . insert ( bound as u8 )
20722075 }
20732076
20742077 pub fn contains ( & self , bound : BuiltinBound ) -> bool {
2075- ( ( self . bits >> ( bound as u8 ) ) & 1 ) == 1
2078+ self . bit_set . contains ( bound as u8 )
20762079 }
20772080
20782081 pub fn iter ( & self ) -> BuiltinBoundsIter {
20792082 self . into_iter ( )
20802083 }
20812084
20822085 fn is_empty ( & self ) -> bool {
2083- self . bits == 0
2086+ self . bit_set . is_empty ( )
20842087 }
20852088
20862089 pub fn to_predicates < ' tcx > ( & self ,
@@ -2095,36 +2098,19 @@ impl BuiltinBounds {
20952098 }
20962099
20972100 pub fn is_superset ( & self , other : & BuiltinBounds ) -> bool {
2098- ( self . bits & other . bits ) == other. bits
2101+ self . bit_set . is_superset ( other. bit_set )
20992102 }
21002103}
21012104
21022105pub struct BuiltinBoundsIter {
2103- bounds : BuiltinBounds ,
2104- index : u8
2106+ bit_set : BitSetIter < u8 >
21052107}
21062108
21072109impl Iterator for BuiltinBoundsIter {
21082110 type Item = BuiltinBound ;
21092111
21102112 fn next ( & mut self ) -> Option < BuiltinBound > {
2111- while self . index < 4 {
2112- let result = match self . index {
2113- 0 if self . bounds . contains ( BuiltinBound :: Send ) => Some ( BuiltinBound :: Send ) ,
2114- 1 if self . bounds . contains ( BuiltinBound :: Sized ) => Some ( BuiltinBound :: Sized ) ,
2115- 2 if self . bounds . contains ( BuiltinBound :: Copy ) => Some ( BuiltinBound :: Copy ) ,
2116- 3 if self . bounds . contains ( BuiltinBound :: Sync ) => Some ( BuiltinBound :: Sync ) ,
2117- _ => None
2118- } ;
2119-
2120- self . index += 1 ;
2121-
2122- if result. is_some ( ) {
2123- return result;
2124- }
2125- }
2126-
2127- return None ;
2113+ self . bit_set . next ( ) . map ( |b| unsafe { mem:: transmute ( b) } )
21282114 }
21292115}
21302116
@@ -2133,10 +2119,11 @@ impl<'a> IntoIterator for &'a BuiltinBounds {
21332119 type IntoIter = BuiltinBoundsIter ;
21342120
21352121 fn into_iter ( self ) -> BuiltinBoundsIter {
2136- BuiltinBoundsIter { bounds : self . clone ( ) , index : 0 }
2122+ BuiltinBoundsIter { bit_set : self . bit_set . into_iter ( ) }
21372123 }
21382124}
21392125
2126+ #[ repr( u8 ) ]
21402127#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , RustcDecodable , RustcEncodable , Hash , Debug ) ]
21412128pub enum BuiltinBound {
21422129 Send ,
0 commit comments