Skip to content

Commit e4c3287

Browse files
committed
Reuse a single work buffer every time the SHA1 message block is processed.
This finally allows the full lib-sha1 test to run in a reasonable amount of time. Was 30s, now 3s. Trims a second or two from stage2/rustc. XFAIL lib-sha1 in stage0 since it will be very slow until the next snapshot.
1 parent 7e7d134 commit e4c3287

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/lib/SHA1.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ state type sha1 = state obj {
3030
// Some unexported constants
3131
const uint digest_buf_len = 5;
3232
const uint msg_block_len = 64;
33+
const uint work_buf_len = 80;
3334

3435
const u32 k0 = 0x5A827999u32;
3536
const u32 k1 = 0x6ED9EBA1u32;
@@ -44,7 +45,8 @@ fn mk_sha1() -> sha1 {
4445
mutable u32 len_high,
4546
vec[mutable u8] msg_block,
4647
mutable uint msg_block_idx,
47-
mutable bool computed);
48+
mutable bool computed,
49+
vec[mutable u32] work_buf);
4850

4951
fn add_input(&sha1state st, &vec[u8] msg) {
5052
// FIXME: Should be typestate precondition
@@ -73,9 +75,10 @@ fn mk_sha1() -> sha1 {
7375

7476
// FIXME: Make precondition
7577
assert (Vec.len(st.h) == digest_buf_len);
78+
assert (Vec.len(st.work_buf) == work_buf_len);
7679

7780
let int t; // Loop counter
78-
let vec[mutable u32] w = Vec.init_elt_mut[u32](0u32, 80u);
81+
auto w = st.work_buf;
7982

8083
// Initialize the first 16 words of the vector w
8184
t = 0;
@@ -279,7 +282,8 @@ fn mk_sha1() -> sha1 {
279282
mutable len_high = 0u32,
280283
msg_block = Vec.init_elt_mut[u8](0u8, msg_block_len),
281284
mutable msg_block_idx = 0u,
282-
mutable computed = false);
285+
mutable computed = false,
286+
work_buf = Vec.init_elt_mut[u32](0u32, work_buf_len));
283287
auto sh = sha1(st);
284288
sh.reset();
285289
ret sh;

src/test/run-pass/lib-sha1.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// -*- rust -*-
22

3+
// xfail-boot
4+
// xfail-stage0
5+
36
use std;
47

58
import std.SHA1;
@@ -35,18 +38,13 @@ fn main() {
3538
0x3Bu8, 0xD2u8, 0x6Eu8, 0xBAu8, 0xAEu8,
3639
0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, 0x29u8,
3740
0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8)
38-
)
39-
// FIXME: This test is disabled because it takes some
40-
// minutes to run under rustboot+valgrind. It may be
41-
// possible to reenable once things are more optimized.
42-
/*,
41+
),
4342
rec(input = a_million_letter_a(),
4443
output = vec(0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8,
4544
0xC4u8, 0xDAu8, 0xA4u8, 0xF6u8, 0x1Eu8,
4645
0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8, 0x27u8,
4746
0x31u8, 0x65u8, 0x34u8, 0x01u8, 0x6Fu8)
4847
)
49-
*/
5048
);
5149

5250
// Examples from wikipedia

0 commit comments

Comments
 (0)