@@ -27,7 +27,7 @@ use util::nodemap::{NodeMap, NodeSet};
2727
2828use serialize:: Encodable ;
2929use std:: cast;
30- use std:: cell:: { Cell , RefCell } ;
30+ use std:: cell:: RefCell ;
3131use std:: hash;
3232use std:: hash:: Hash ;
3333use std:: io:: MemWriter ;
@@ -76,26 +76,9 @@ pub struct EncodeParams<'a> {
7676 pub encode_inlined_item: EncodeInlinedItem <' a>,
7777}
7878
79- pub struct Stats {
80- inline_bytes : Cell < u64 > ,
81- attr_bytes : Cell < u64 > ,
82- dep_bytes : Cell < u64 > ,
83- lang_item_bytes : Cell < u64 > ,
84- native_lib_bytes : Cell < u64 > ,
85- macro_registrar_fn_bytes : Cell < u64 > ,
86- macro_defs_bytes : Cell < u64 > ,
87- impl_bytes : Cell < u64 > ,
88- misc_bytes : Cell < u64 > ,
89- item_bytes : Cell < u64 > ,
90- index_bytes : Cell < u64 > ,
91- zero_bytes : Cell < u64 > ,
92- total_bytes : Cell < u64 > ,
93- }
94-
9579pub struct EncodeContext < ' a > {
9680 pub diag : & ' a SpanHandler ,
9781 pub tcx : & ' a ty:: ctxt ,
98- pub stats : @Stats ,
9982 pub reexports2 : & ' a middle:: resolve:: ExportMap2 ,
10083 pub item_symbols : & ' a RefCell < NodeMap < ~str > > ,
10184 pub non_inlineable_statics : & ' a RefCell < NodeSet > ,
@@ -1701,20 +1684,33 @@ pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec<u8> {
17011684}
17021685
17031686fn encode_metadata_inner ( wr : & mut MemWriter , parms : EncodeParams , krate : & Crate ) {
1704- let stats = Stats {
1705- inline_bytes : Cell :: new ( 0 ) ,
1706- attr_bytes : Cell :: new ( 0 ) ,
1707- dep_bytes : Cell :: new ( 0 ) ,
1708- lang_item_bytes : Cell :: new ( 0 ) ,
1709- native_lib_bytes : Cell :: new ( 0 ) ,
1710- macro_registrar_fn_bytes : Cell :: new ( 0 ) ,
1711- macro_defs_bytes : Cell :: new ( 0 ) ,
1712- impl_bytes : Cell :: new ( 0 ) ,
1713- misc_bytes : Cell :: new ( 0 ) ,
1714- item_bytes : Cell :: new ( 0 ) ,
1715- index_bytes : Cell :: new ( 0 ) ,
1716- zero_bytes : Cell :: new ( 0 ) ,
1717- total_bytes : Cell :: new ( 0 ) ,
1687+ struct Stats {
1688+ attr_bytes : u64 ,
1689+ dep_bytes : u64 ,
1690+ lang_item_bytes : u64 ,
1691+ native_lib_bytes : u64 ,
1692+ macro_registrar_fn_bytes : u64 ,
1693+ macro_defs_bytes : u64 ,
1694+ impl_bytes : u64 ,
1695+ misc_bytes : u64 ,
1696+ item_bytes : u64 ,
1697+ index_bytes : u64 ,
1698+ zero_bytes : u64 ,
1699+ total_bytes : u64 ,
1700+ }
1701+ let mut stats = Stats {
1702+ attr_bytes : 0 ,
1703+ dep_bytes : 0 ,
1704+ lang_item_bytes : 0 ,
1705+ native_lib_bytes : 0 ,
1706+ macro_registrar_fn_bytes : 0 ,
1707+ macro_defs_bytes : 0 ,
1708+ impl_bytes : 0 ,
1709+ misc_bytes : 0 ,
1710+ item_bytes : 0 ,
1711+ index_bytes : 0 ,
1712+ zero_bytes : 0 ,
1713+ total_bytes : 0 ,
17181714 } ;
17191715 let EncodeParams {
17201716 item_symbols,
@@ -1730,7 +1726,6 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate)
17301726 let ecx = EncodeContext {
17311727 diag : diag,
17321728 tcx : tcx,
1733- stats : @stats,
17341729 reexports2 : reexports2,
17351730 item_symbols : item_symbols,
17361731 non_inlineable_statics : non_inlineable_statics,
@@ -1748,76 +1743,75 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate)
17481743 let mut i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17491744 let crate_attrs = synthesize_crate_attrs ( & ecx, krate) ;
17501745 encode_attributes ( & mut ebml_w, crate_attrs. as_slice ( ) ) ;
1751- ecx . stats . attr_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1746+ stats. attr_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17521747
17531748 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17541749 encode_crate_deps ( & mut ebml_w, ecx. cstore ) ;
1755- ecx . stats . dep_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1750+ stats. dep_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17561751
17571752 // Encode the language items.
17581753 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17591754 encode_lang_items ( & ecx, & mut ebml_w) ;
1760- ecx . stats . lang_item_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1755+ stats. lang_item_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17611756
17621757 // Encode the native libraries used
17631758 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17641759 encode_native_libraries ( & ecx, & mut ebml_w) ;
1765- ecx . stats . native_lib_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1760+ stats. native_lib_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17661761
17671762 // Encode the macro registrar function
17681763 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17691764 encode_macro_registrar_fn ( & ecx, & mut ebml_w) ;
1770- ecx . stats . macro_registrar_fn_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1765+ stats. macro_registrar_fn_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17711766
17721767 // Encode macro definitions
17731768 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17741769 encode_macro_defs ( & ecx, krate, & mut ebml_w) ;
1775- ecx . stats . macro_defs_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1770+ stats. macro_defs_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17761771
17771772 // Encode the def IDs of impls, for coherence checking.
17781773 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17791774 encode_impls ( & ecx, krate, & mut ebml_w) ;
1780- ecx . stats . impl_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1775+ stats. impl_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17811776
17821777 // Encode miscellaneous info.
17831778 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17841779 encode_misc_info ( & ecx, krate, & mut ebml_w) ;
1785- ecx . stats . misc_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1780+ stats. misc_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17861781
17871782 // Encode and index the items.
17881783 ebml_w. start_tag ( tag_items) ;
17891784 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17901785 let items_index = encode_info_for_items ( & ecx, & mut ebml_w, krate) ;
1791- ecx . stats . item_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1786+ stats. item_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17921787
17931788 i = ebml_w. writer . tell ( ) . unwrap ( ) ;
17941789 encode_index ( & mut ebml_w, items_index, write_i64) ;
1795- ecx . stats . index_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) - i) ;
1790+ stats. index_bytes = ebml_w. writer . tell ( ) . unwrap ( ) - i;
17961791 ebml_w. end_tag ( ) ;
17971792
1798- ecx . stats . total_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) ) ;
1793+ stats. total_bytes = ebml_w. writer . tell ( ) . unwrap ( ) ;
17991794
18001795 if tcx. sess . meta_stats ( ) {
18011796 for e in ebml_w. writer . get_ref ( ) . iter ( ) {
18021797 if * e == 0 {
1803- ecx . stats . zero_bytes . set ( ecx . stats . zero_bytes . get ( ) + 1 ) ;
1798+ stats. zero_bytes += 1 ;
18041799 }
18051800 }
18061801
18071802 println ! ( "metadata stats:" ) ;
1808- println ! ( " inline bytes: {}" , ecx. stats. inline_bytes. get( ) ) ;
1809- println ! ( " attribute bytes: {}" , ecx. stats. attr_bytes. get( ) ) ;
1810- println ! ( " dep bytes: {}" , ecx. stats. dep_bytes. get( ) ) ;
1811- println ! ( " lang item bytes: {}" , ecx. stats. lang_item_bytes. get( ) ) ;
1812- println ! ( " native bytes: {}" , ecx. stats. native_lib_bytes. get( ) ) ;
1813- println ! ( "macro registrar bytes: {}" , ecx. stats. macro_registrar_fn_bytes. get( ) ) ;
1814- println ! ( " macro def bytes: {}" , ecx. stats. macro_defs_bytes. get( ) ) ;
1815- println ! ( " impl bytes: {}" , ecx. stats. impl_bytes. get( ) ) ;
1816- println ! ( " misc bytes: {}" , ecx. stats. misc_bytes. get( ) ) ;
1817- println ! ( " item bytes: {}" , ecx. stats. item_bytes. get( ) ) ;
1818- println ! ( " index bytes: {}" , ecx. stats. index_bytes. get( ) ) ;
1819- println ! ( " zero bytes: {}" , ecx. stats. zero_bytes. get( ) ) ;
1820- println ! ( " total bytes: {}" , ecx. stats. total_bytes. get( ) ) ;
1803+ println ! ( " attribute bytes: {}" , stats. attr_bytes) ;
1804+ println ! ( " dep bytes: {}" , stats. dep_bytes) ;
1805+ println ! ( " lang item bytes: {}" , stats. lang_item_bytes) ;
1806+ println ! ( " native bytes: {}" , stats. native_lib_bytes) ;
1807+ println ! ( "macro registrar bytes: {}" , stats. macro_registrar_fn_bytes) ;
1808+ println ! ( " macro def bytes: {}" , stats. macro_defs_bytes) ;
1809+ println ! ( " impl bytes: {}" , stats. impl_bytes) ;
1810+ println ! ( " misc bytes: {}" , stats. misc_bytes) ;
1811+ println ! ( " item bytes: {}" , stats. item_bytes) ;
1812+ println ! ( " index bytes: {}" , stats. index_bytes) ;
1813+ println ! ( " zero bytes: {}" , stats. zero_bytes) ;
1814+ println ! ( " total bytes: {}" , stats. total_bytes) ;
18211815 }
18221816}
18231817
0 commit comments