11
11
// ignore-android see #10393 #13206
12
12
// ignore-pretty
13
13
14
- use std:: ascii:: OwnedStrAsciiExt ;
15
- use std:: str;
16
14
use std:: strbuf:: StrBuf ;
17
15
use std:: slice;
18
16
@@ -50,8 +48,7 @@ impl Code {
50
48
string. bytes ( ) . fold ( Code ( 0u64 ) , |a, b| a. push_char ( b) )
51
49
}
52
50
53
- // FIXME: Inefficient.
54
- fn unpack ( & self , frame : uint ) -> ~str {
51
+ fn unpack ( & self , frame : uint ) -> StrBuf {
55
52
let mut key = self . hash ( ) ;
56
53
let mut result = Vec :: new ( ) ;
57
54
for _ in range ( 0 , frame) {
@@ -60,7 +57,7 @@ impl Code {
60
57
}
61
58
62
59
result. reverse ( ) ;
63
- str :: from_utf8_owned ( result. move_iter ( ) . collect ( ) ) . unwrap ( )
60
+ StrBuf :: from_utf8 ( result) . unwrap ( )
64
61
}
65
62
}
66
63
@@ -239,7 +236,7 @@ fn print_frequencies(frequencies: &Table, frame: uint) {
239
236
240
237
for & ( count, key) in vector. iter ( ) . rev ( ) {
241
238
println ! ( "{} {:.3f}" ,
242
- key. unpack( frame) ,
239
+ key. unpack( frame) . as_slice ( ) ,
243
240
( count as f32 * 100.0 ) / ( total_count as f32 ) ) ;
244
241
}
245
242
println ! ( "" ) ;
@@ -249,14 +246,17 @@ fn print_occurrences(frequencies: &mut Table, occurrence: &'static str) {
249
246
frequencies. lookup ( Code :: pack ( occurrence) , PrintCallback ( occurrence) )
250
247
}
251
248
252
- fn get_sequence < R : Buffer > ( r : & mut R , key : & str ) -> ~ [ u8 ] {
253
- let mut res = StrBuf :: new ( ) ;
249
+ fn get_sequence < R : Buffer > ( r : & mut R , key : & str ) -> Vec < u8 > {
250
+ let mut res = Vec :: new ( ) ;
254
251
for l in r. lines ( ) . map ( |l| l. ok ( ) . unwrap ( ) )
255
252
. skip_while ( |l| key != l. slice_to ( key. len ( ) ) ) . skip ( 1 )
256
253
{
257
- res. push_str ( l. trim ( ) ) ;
254
+ res. push_all ( l. trim ( ) . as_bytes ( ) ) ;
258
255
}
259
- res. to_owned_str ( ) . into_ascii_upper ( ) . into_bytes ( )
256
+ for b in res. mut_iter ( ) {
257
+ * b = b. to_ascii ( ) . to_upper ( ) . to_byte ( ) ;
258
+ }
259
+ res
260
260
}
261
261
262
262
fn main ( ) {
@@ -268,17 +268,17 @@ fn main() {
268
268
} ;
269
269
270
270
let mut frequencies = Table :: new ( ) ;
271
- generate_frequencies ( & mut frequencies, input, 1 ) ;
271
+ generate_frequencies ( & mut frequencies, input. as_slice ( ) , 1 ) ;
272
272
print_frequencies ( & frequencies, 1 ) ;
273
273
274
274
frequencies = Table :: new ( ) ;
275
- generate_frequencies ( & mut frequencies, input, 2 ) ;
275
+ generate_frequencies ( & mut frequencies, input. as_slice ( ) , 2 ) ;
276
276
print_frequencies ( & frequencies, 2 ) ;
277
277
278
278
for occurrence in OCCURRENCES . iter ( ) {
279
279
frequencies = Table :: new ( ) ;
280
280
generate_frequencies ( & mut frequencies,
281
- input,
281
+ input. as_slice ( ) ,
282
282
occurrence. len ( ) ) ;
283
283
print_occurrences ( & mut frequencies, * occurrence) ;
284
284
}
0 commit comments