7
7
// option. This file may not be copied, modified, or distributed
8
8
// except according to those terms.
9
9
10
- #![ feature( core) ]
11
-
12
10
extern crate csv;
13
11
extern crate string_cache;
12
+ extern crate string_cache_shared;
14
13
extern crate rustc_serialize;
15
14
16
15
use string_cache:: Atom ;
17
- use string_cache:: atom:: repr;
18
16
19
17
use std:: { env, cmp} ;
20
- use std:: num:: FromPrimitive ;
21
18
use std:: collections:: hash_map:: { HashMap , Entry } ;
22
19
use std:: path:: Path ;
23
20
@@ -28,14 +25,32 @@ struct Event {
28
25
string : Option < String > ,
29
26
}
30
27
31
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , FromPrimitive ) ]
32
- #[ repr( u8 ) ]
28
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
33
29
enum Kind {
34
30
Dynamic ,
35
31
Inline ,
36
32
Static ,
37
33
}
38
34
35
+ impl Kind {
36
+ fn from_tag ( tag : u8 ) -> Kind {
37
+ match tag {
38
+ string_cache_shared:: DYNAMIC_TAG => Kind :: Dynamic ,
39
+ string_cache_shared:: INLINE_TAG => Kind :: Inline ,
40
+ string_cache_shared:: STATIC_TAG => Kind :: Static ,
41
+ _ => panic ! ( )
42
+ }
43
+ }
44
+
45
+ fn to_tag ( self ) -> u8 {
46
+ match self {
47
+ Kind :: Dynamic => string_cache_shared:: DYNAMIC_TAG ,
48
+ Kind :: Inline => string_cache_shared:: INLINE_TAG ,
49
+ Kind :: Static => string_cache_shared:: STATIC_TAG ,
50
+ }
51
+ }
52
+ }
53
+
39
54
#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
40
55
struct Summary {
41
56
kind : Kind ,
@@ -62,10 +77,10 @@ fn main() {
62
77
match & ev. event [ ..] {
63
78
"intern" => {
64
79
let tag = ( ev. id & 0xf ) as u8 ;
65
- assert ! ( tag <= repr :: STATIC_TAG ) ;
80
+ assert ! ( tag <= string_cache_shared :: STATIC_TAG ) ;
66
81
67
82
let string = match tag {
68
- repr :: DYNAMIC_TAG => dynamic[ & ev. id ] . clone ( ) ,
83
+ string_cache_shared :: DYNAMIC_TAG => dynamic[ & ev. id ] . clone ( ) ,
69
84
70
85
// FIXME: We really shouldn't be allowed to do this. It's a memory-safety
71
86
// hazard; the field is only public for the atom!() macro.
@@ -76,7 +91,7 @@ fn main() {
76
91
Entry :: Occupied ( entry) => entry. into_mut ( ) . times += 1 ,
77
92
Entry :: Vacant ( entry) => {
78
93
entry. insert ( Summary {
79
- kind : FromPrimitive :: from_u8 ( tag) . unwrap ( ) ,
94
+ kind : Kind :: from_tag ( tag) ,
80
95
times : 1 ,
81
96
} ) ;
82
97
}
@@ -118,14 +133,14 @@ fn main() {
118
133
let mut by_kind = [ 0 , 0 , 0 ] ;
119
134
for & ( _, Summary { kind, times } ) in & summary {
120
135
total += times;
121
- by_kind[ kind as usize ] += times;
136
+ by_kind[ kind. to_tag ( ) as usize ] += times;
122
137
}
123
138
124
139
println ! ( "\n " ) ;
125
140
println ! ( "kind times pct" ) ;
126
141
println ! ( "------- ------- ----" ) ;
127
142
for ( k, & n) in by_kind. iter ( ) . enumerate ( ) {
128
- let k: Kind = FromPrimitive :: from_usize ( k ) . unwrap ( ) ;
143
+ let k: Kind = Kind :: from_tag ( k as u8 ) ;
129
144
print ! ( "{:7?} {:7} {:4.1}" ,
130
145
k, n, 100.0 * ( n as f64 ) / ( total as f64 ) ) ;
131
146
0 commit comments