aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-05-11 01:12:37 -0400
committerBrian Anderson <[email protected]>2011-05-11 01:38:17 -0400
commite4c32873674ce31f0ace47e7ac08266f3e86d6a0 (patch)
tree2e7738b2985cccaa261cd3819d05b68ce8278cd5
parentRemove unnecessary array access from SHA1 (diff)
downloadrust-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.
-rw-r--r--src/lib/SHA1.rs10
-rw-r--r--src/test/run-pass/lib-sha1.rs10
2 files changed, 11 insertions, 9 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;
diff --git a/src/test/run-pass/lib-sha1.rs b/src/test/run-pass/lib-sha1.rs
index 2a7e8646..c89eca59 100644
--- a/src/test/run-pass/lib-sha1.rs
+++ b/src/test/run-pass/lib-sha1.rs
@@ -1,5 +1,8 @@
// -*- rust -*-
+// xfail-boot
+// xfail-stage0
+
use std;
import std.SHA1;
@@ -35,18 +38,13 @@ fn main() {
0x3Bu8, 0xD2u8, 0x6Eu8, 0xBAu8, 0xAEu8,
0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, 0x29u8,
0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8)
- )
- // FIXME: This test is disabled because it takes some
- // minutes to run under rustboot+valgrind. It may be
- // possible to reenable once things are more optimized.
- /*,
+ ),
rec(input = a_million_letter_a(),
output = vec(0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8,
0xC4u8, 0xDAu8, 0xA4u8, 0xF6u8, 0x1Eu8,
0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8, 0x27u8,
0x31u8, 0x65u8, 0x34u8, 0x01u8, 0x6Fu8)
)
- */
);
// Examples from wikipedia