@@ -12,7 +12,6 @@ pub use self::error::{EvalError, EvalResult, EvalErrorKind, AssertMessage};
1212
1313pub use self :: value:: { PrimVal , PrimValKind , Value , Pointer , ConstValue } ;
1414
15- use std:: collections:: BTreeMap ;
1615use std:: fmt;
1716use mir;
1817use hir:: def_id:: DefId ;
@@ -21,9 +20,11 @@ use ty::layout::{self, Align, HasDataLayout, Size};
2120use middle:: region;
2221use std:: iter;
2322use std:: io;
23+ use std:: ops:: { Deref , DerefMut } ;
2424use std:: hash:: Hash ;
2525use syntax:: ast:: Mutability ;
2626use rustc_serialize:: { Encoder , Decoder , Decodable , Encodable } ;
27+ use rustc_data_structures:: sorted_map:: SortedMap ;
2728use rustc_data_structures:: fx:: FxHashMap ;
2829use byteorder:: { WriteBytesExt , ReadBytesExt , LittleEndian , BigEndian } ;
2930
@@ -341,7 +342,7 @@ pub struct Allocation {
341342 pub bytes : Vec < u8 > ,
342343 /// Maps from byte addresses to allocations.
343344 /// Only the first byte of a pointer is inserted into the map.
344- pub relocations : BTreeMap < Size , AllocId > ,
345+ pub relocations : Relocations ,
345346 /// Denotes undefined memory. Reading from undefined memory is forbidden in miri
346347 pub undef_mask : UndefMask ,
347348 /// The alignment of the allocation to detect unaligned reads.
@@ -358,7 +359,7 @@ impl Allocation {
358359 undef_mask. grow ( Size :: from_bytes ( slice. len ( ) as u64 ) , true ) ;
359360 Self {
360361 bytes : slice. to_owned ( ) ,
361- relocations : BTreeMap :: new ( ) ,
362+ relocations : Relocations :: new ( ) ,
362363 undef_mask,
363364 align,
364365 runtime_mutability : Mutability :: Immutable ,
@@ -373,7 +374,7 @@ impl Allocation {
373374 assert_eq ! ( size. bytes( ) as usize as u64 , size. bytes( ) ) ;
374375 Allocation {
375376 bytes : vec ! [ 0 ; size. bytes( ) as usize ] ,
376- relocations : BTreeMap :: new ( ) ,
377+ relocations : Relocations :: new ( ) ,
377378 undef_mask : UndefMask :: new ( size) ,
378379 align,
379380 runtime_mutability : Mutability :: Immutable ,
@@ -383,6 +384,35 @@ impl Allocation {
383384
384385impl < ' tcx > :: serialize:: UseSpecializedDecodable for & ' tcx Allocation { }
385386
387+ #[ derive( Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
388+ pub struct Relocations ( SortedMap < Size , AllocId > ) ;
389+
390+ impl Relocations {
391+ pub fn new ( ) -> Relocations {
392+ Relocations ( SortedMap :: new ( ) )
393+ }
394+
395+ // The caller must guarantee that the given relocations are already sorted
396+ // by address and contain no duplicates.
397+ pub fn from_presorted ( r : Vec < ( Size , AllocId ) > ) -> Relocations {
398+ Relocations ( SortedMap :: from_presorted_elements ( r) )
399+ }
400+ }
401+
402+ impl Deref for Relocations {
403+ type Target = SortedMap < Size , AllocId > ;
404+
405+ fn deref ( & self ) -> & Self :: Target {
406+ & self . 0
407+ }
408+ }
409+
410+ impl DerefMut for Relocations {
411+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
412+ & mut self . 0
413+ }
414+ }
415+
386416////////////////////////////////////////////////////////////////////////////////
387417// Methods to access integers in the target endianness
388418////////////////////////////////////////////////////////////////////////////////
0 commit comments