diff options
| author | Brian Anderson <[email protected]> | 2011-05-11 01:12:37 -0400 |
|---|---|---|
| committer | Brian Anderson <[email protected]> | 2011-05-11 01:38:17 -0400 |
| commit | e4c32873674ce31f0ace47e7ac08266f3e86d6a0 (patch) | |
| tree | 2e7738b2985cccaa261cd3819d05b68ce8278cd5 /src/lib | |
| parent | Remove unnecessary array access from SHA1 (diff) | |
| download | rust-e4c32873674ce31f0ace47e7ac08266f3e86d6a0.tar.xz rust-e4c32873674ce31f0ace47e7ac08266f3e86d6a0.zip | |
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.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/SHA1.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/SHA1.rs b/src/lib/SHA1.rs index 93b06a51..6aec814c 100644 --- a/src/lib/SHA1.rs +++ b/src/lib/SHA1.rs @@ -30,6 +30,7 @@ state type sha1 = state obj { // Some unexported constants const uint digest_buf_len = 5; const uint msg_block_len = 64; +const uint work_buf_len = 80; const u32 k0 = 0x5A827999u32; const u32 k1 = 0x6ED9EBA1u32; @@ -44,7 +45,8 @@ fn mk_sha1() -> sha1 { mutable u32 len_high, vec[mutable u8] msg_block, mutable uint msg_block_idx, - mutable bool computed); + mutable bool computed, + vec[mutable u32] work_buf); fn add_input(&sha1state st, &vec[u8] msg) { // FIXME: Should be typestate precondition @@ -73,9 +75,10 @@ fn mk_sha1() -> sha1 { // FIXME: Make precondition assert (Vec.len(st.h) == digest_buf_len); + assert (Vec.len(st.work_buf) == work_buf_len); let int t; // Loop counter - let vec[mutable u32] w = Vec.init_elt_mut[u32](0u32, 80u); + auto w = st.work_buf; // Initialize the first 16 words of the vector w t = 0; @@ -279,7 +282,8 @@ fn mk_sha1() -> sha1 { mutable len_high = 0u32, msg_block = Vec.init_elt_mut[u8](0u8, msg_block_len), mutable msg_block_idx = 0u, - mutable computed = false); + mutable computed = false, + work_buf = Vec.init_elt_mut[u32](0u32, work_buf_len)); auto sh = sha1(st); sh.reset(); ret sh; |