@@ -27,7 +27,7 @@ use util::nodemap::{NodeMap, NodeSet};
27
27
28
28
use serialize:: Encodable ;
29
29
use std:: cast;
30
- use std:: cell:: { Cell , RefCell } ;
30
+ use std:: cell:: RefCell ;
31
31
use std:: hash;
32
32
use std:: hash:: Hash ;
33
33
use std:: io:: MemWriter ;
@@ -76,26 +76,9 @@ pub struct EncodeParams<'a> {
76
76
pub encode_inlined_item: EncodeInlinedItem <' a>,
77
77
}
78
78
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
-
95
79
pub struct EncodeContext < ' a > {
96
80
pub diag : & ' a SpanHandler ,
97
81
pub tcx : & ' a ty:: ctxt ,
98
- pub stats : @Stats ,
99
82
pub reexports2 : & ' a middle:: resolve:: ExportMap2 ,
100
83
pub item_symbols : & ' a RefCell < NodeMap < ~str > > ,
101
84
pub non_inlineable_statics : & ' a RefCell < NodeSet > ,
@@ -1701,20 +1684,33 @@ pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec<u8> {
1701
1684
}
1702
1685
1703
1686
fn 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 ,
1718
1714
} ;
1719
1715
let EncodeParams {
1720
1716
item_symbols,
@@ -1730,7 +1726,6 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate)
1730
1726
let ecx = EncodeContext {
1731
1727
diag : diag,
1732
1728
tcx : tcx,
1733
- stats : @stats,
1734
1729
reexports2 : reexports2,
1735
1730
item_symbols : item_symbols,
1736
1731
non_inlineable_statics : non_inlineable_statics,
@@ -1748,76 +1743,75 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate)
1748
1743
let mut i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1749
1744
let crate_attrs = synthesize_crate_attrs ( & ecx, krate) ;
1750
1745
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;
1752
1747
1753
1748
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1754
1749
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;
1756
1751
1757
1752
// Encode the language items.
1758
1753
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1759
1754
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;
1761
1756
1762
1757
// Encode the native libraries used
1763
1758
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1764
1759
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;
1766
1761
1767
1762
// Encode the macro registrar function
1768
1763
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1769
1764
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;
1771
1766
1772
1767
// Encode macro definitions
1773
1768
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1774
1769
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;
1776
1771
1777
1772
// Encode the def IDs of impls, for coherence checking.
1778
1773
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1779
1774
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;
1781
1776
1782
1777
// Encode miscellaneous info.
1783
1778
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1784
1779
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;
1786
1781
1787
1782
// Encode and index the items.
1788
1783
ebml_w. start_tag ( tag_items) ;
1789
1784
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1790
1785
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;
1792
1787
1793
1788
i = ebml_w. writer . tell ( ) . unwrap ( ) ;
1794
1789
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;
1796
1791
ebml_w. end_tag ( ) ;
1797
1792
1798
- ecx . stats . total_bytes . set ( ebml_w. writer . tell ( ) . unwrap ( ) ) ;
1793
+ stats. total_bytes = ebml_w. writer . tell ( ) . unwrap ( ) ;
1799
1794
1800
1795
if tcx. sess . meta_stats ( ) {
1801
1796
for e in ebml_w. writer . get_ref ( ) . iter ( ) {
1802
1797
if * e == 0 {
1803
- ecx . stats . zero_bytes . set ( ecx . stats . zero_bytes . get ( ) + 1 ) ;
1798
+ stats. zero_bytes += 1 ;
1804
1799
}
1805
1800
}
1806
1801
1807
1802
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) ;
1821
1815
}
1822
1816
}
1823
1817
0 commit comments