@@ -35,8 +35,6 @@ use rustc_data_structures::stable_hasher::StableHasher;
35
35
use rustc_serialize:: { Encodable , Encoder , SpecializedEncoder , opaque} ;
36
36
37
37
use std:: hash:: Hash ;
38
- use std:: io:: prelude:: * ;
39
- use std:: io:: Cursor ;
40
38
use std:: path:: Path ;
41
39
use rustc_data_structures:: sync:: Lrc ;
42
40
use std:: u32;
@@ -52,7 +50,7 @@ use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
52
50
use rustc:: hir:: intravisit;
53
51
54
52
pub struct EncodeContext < ' a , ' tcx : ' a > {
55
- opaque : opaque:: Encoder < ' a > ,
53
+ opaque : opaque:: Encoder ,
56
54
pub tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
57
55
link_meta : & ' a LinkMeta ,
58
56
@@ -76,7 +74,7 @@ macro_rules! encoder_methods {
76
74
}
77
75
78
76
impl < ' a , ' tcx > Encoder for EncodeContext < ' a , ' tcx > {
79
- type Error = <opaque:: Encoder < ' a > as Encoder >:: Error ;
77
+ type Error = <opaque:: Encoder as Encoder >:: Error ;
80
78
81
79
fn emit_nil ( & mut self ) -> Result < ( ) , Self :: Error > {
82
80
Ok ( ( ) )
@@ -480,7 +478,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
480
478
481
479
// Index the items
482
480
i = self . position ( ) ;
483
- let index = items. write_index ( & mut self . opaque . cursor ) ;
481
+ let index = items. write_index ( & mut self . opaque ) ;
484
482
let index_bytes = self . position ( ) - i;
485
483
486
484
let attrs = tcx. hir . krate_attrs ( ) ;
@@ -537,7 +535,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
537
535
538
536
if self . tcx . sess . meta_stats ( ) {
539
537
let mut zero_bytes = 0 ;
540
- for e in self . opaque . cursor . get_ref ( ) {
538
+ for e in self . opaque . data . iter ( ) {
541
539
if * e == 0 {
542
540
zero_bytes += 1 ;
543
541
}
@@ -1797,15 +1795,15 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1797
1795
link_meta : & LinkMeta )
1798
1796
-> EncodedMetadata
1799
1797
{
1800
- let mut cursor = Cursor :: new ( vec ! [ ] ) ;
1801
- cursor . write_all ( METADATA_HEADER ) . unwrap ( ) ;
1798
+ let mut encoder = opaque :: Encoder :: new ( vec ! [ ] ) ;
1799
+ encoder . emit_raw_bytes ( METADATA_HEADER ) ;
1802
1800
1803
1801
// Will be filled with the root position after encoding everything.
1804
- cursor . write_all ( & [ 0 , 0 , 0 , 0 ] ) . unwrap ( ) ;
1802
+ encoder . emit_raw_bytes ( & [ 0 , 0 , 0 , 0 ] ) ;
1805
1803
1806
- let root = {
1804
+ let ( root, mut result ) = {
1807
1805
let mut ecx = EncodeContext {
1808
- opaque : opaque :: Encoder :: new ( & mut cursor ) ,
1806
+ opaque : encoder ,
1809
1807
tcx,
1810
1808
link_meta,
1811
1809
lazy_state : LazyState :: NoNode ,
@@ -1821,9 +1819,9 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1821
1819
1822
1820
// Encode all the entries and extra information in the crate,
1823
1821
// culminating in the `CrateRoot` which points to all of it.
1824
- ecx. encode_crate_root ( )
1822
+ let root = ecx. encode_crate_root ( ) ;
1823
+ ( root, ecx. opaque . into_inner ( ) )
1825
1824
} ;
1826
- let mut result = cursor. into_inner ( ) ;
1827
1825
1828
1826
// Encode the root position.
1829
1827
let header = METADATA_HEADER . len ( ) ;
0 commit comments