Skip to content

Commit ad74fde

Browse files
blake2-ppcthestinger
authored andcommitted
Use std::iter::range_step
Use the iterator version instead of the old uint::/int::range_step functions.
1 parent 66c2965 commit ad74fde

File tree

7 files changed

+57
-77
lines changed

7 files changed

+57
-77
lines changed

src/libextra/crypto/md5.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::uint;
11+
use std::iter::range_step;
1212

1313
use cryptoutil::{write_u32_le, read_u32v_le, FixedBuffer, FixedBuffer64, StandardPadding};
1414
use digest::Digest;
@@ -86,46 +86,42 @@ impl Md5State {
8686
read_u32v_le(data, input);
8787

8888
// round 1
89-
do uint::range_step(0, 16, 4) |i| {
89+
for i in range_step(0u, 16, 4) {
9090
a = op_f(a, b, c, d, data[i] + C1[i], 7);
9191
d = op_f(d, a, b, c, data[i + 1] + C1[i + 1], 12);
9292
c = op_f(c, d, a, b, data[i + 2] + C1[i + 2], 17);
9393
b = op_f(b, c, d, a, data[i + 3] + C1[i + 3], 22);
94-
true
95-
};
94+
}
9695

9796
// round 2
9897
let mut t = 1;
99-
do uint::range_step(0, 16, 4) |i| {
98+
for i in range_step(0u, 16, 4) {
10099
a = op_g(a, b, c, d, data[t & 0x0f] + C2[i], 5);
101100
d = op_g(d, a, b, c, data[(t + 5) & 0x0f] + C2[i + 1], 9);
102101
c = op_g(c, d, a, b, data[(t + 10) & 0x0f] + C2[i + 2], 14);
103102
b = op_g(b, c, d, a, data[(t + 15) & 0x0f] + C2[i + 3], 20);
104103
t += 20;
105-
true
106-
};
104+
}
107105

108106
// round 3
109107
t = 5;
110-
do uint::range_step(0, 16, 4) |i| {
108+
for i in range_step(0u, 16, 4) {
111109
a = op_h(a, b, c, d, data[t & 0x0f] + C3[i], 4);
112110
d = op_h(d, a, b, c, data[(t + 3) & 0x0f] + C3[i + 1], 11);
113111
c = op_h(c, d, a, b, data[(t + 6) & 0x0f] + C3[i + 2], 16);
114112
b = op_h(b, c, d, a, data[(t + 9) & 0x0f] + C3[i + 3], 23);
115113
t += 12;
116-
true
117-
};
114+
}
118115

119116
// round 4
120117
t = 0;
121-
do uint::range_step(0, 16, 4) |i| {
118+
for i in range_step(0u, 16, 4) {
122119
a = op_i(a, b, c, d, data[t & 0x0f] + C4[i], 6);
123120
d = op_i(d, a, b, c, data[(t + 7) & 0x0f] + C4[i + 1], 10);
124121
c = op_i(c, d, a, b, data[(t + 14) & 0x0f] + C4[i + 2], 15);
125122
b = op_i(b, c, d, a, data[(t + 21) & 0x0f] + C4[i + 3], 21);
126123
t += 28;
127-
true
128-
};
124+
}
129125

130126
self.s0 += a;
131127
self.s1 += b;

src/libextra/crypto/sha2.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::uint;
11+
use std::iter::range_step;
1212

1313
use cryptoutil::{write_u64_be, write_u32_be, read_u64v_be, read_u32v_be, add_bytes_to_bits,
1414
add_bytes_to_bits_tuple, FixedBuffer, FixedBuffer128, FixedBuffer64, StandardPadding};
@@ -111,7 +111,7 @@ impl Engine512State {
111111

112112
// Putting the message schedule inside the same loop as the round calculations allows for
113113
// the compiler to generate better code.
114-
do uint::range_step(0, 64, 8) |t| {
114+
for t in range_step(0u, 64, 8) {
115115
schedule_round!(t + 16);
116116
schedule_round!(t + 17);
117117
schedule_round!(t + 18);
@@ -129,10 +129,9 @@ impl Engine512State {
129129
sha2_round!(d, e, f, g, h, a, b, c, K64, t + 5);
130130
sha2_round!(c, d, e, f, g, h, a, b, K64, t + 6);
131131
sha2_round!(b, c, d, e, f, g, h, a, K64, t + 7);
132-
true
133-
};
132+
}
134133

135-
do uint::range_step(64, 80, 8) |t| {
134+
for t in range_step(64u, 80, 8) {
136135
sha2_round!(a, b, c, d, e, f, g, h, K64, t);
137136
sha2_round!(h, a, b, c, d, e, f, g, K64, t + 1);
138137
sha2_round!(g, h, a, b, c, d, e, f, K64, t + 2);
@@ -141,8 +140,7 @@ impl Engine512State {
141140
sha2_round!(d, e, f, g, h, a, b, c, K64, t + 5);
142141
sha2_round!(c, d, e, f, g, h, a, b, K64, t + 6);
143142
sha2_round!(b, c, d, e, f, g, h, a, K64, t + 7);
144-
true
145-
};
143+
}
146144

147145
self.H0 += a;
148146
self.H1 += b;
@@ -527,7 +525,7 @@ impl Engine256State {
527525

528526
// Putting the message schedule inside the same loop as the round calculations allows for
529527
// the compiler to generate better code.
530-
do uint::range_step(0, 48, 8) |t| {
528+
for t in range_step(0u, 48, 8) {
531529
schedule_round!(t + 16);
532530
schedule_round!(t + 17);
533531
schedule_round!(t + 18);
@@ -545,10 +543,9 @@ impl Engine256State {
545543
sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5);
546544
sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6);
547545
sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7);
548-
true
549-
};
546+
}
550547

551-
do uint::range_step(48, 64, 8) |t| {
548+
for t in range_step(48u, 64, 8) {
552549
sha2_round!(a, b, c, d, e, f, g, h, K32, t);
553550
sha2_round!(h, a, b, c, d, e, f, g, K32, t + 1);
554551
sha2_round!(g, h, a, b, c, d, e, f, K32, t + 2);
@@ -557,8 +554,7 @@ impl Engine256State {
557554
sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5);
558555
sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6);
559556
sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7);
560-
true
561-
};
557+
}
562558

563559
self.H0 += a;
564560
self.H1 += b;

src/libstd/char.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use cast::transmute;
1414
use option::{None, Option, Some};
15-
use i32;
15+
use iter::{Iterator, range_step};
1616
use str::StrSlice;
1717
use unicode::{derived_property, general_category, decompose};
1818
use to_str::ToStr;
@@ -286,15 +286,14 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
286286
(c <= '\uffff') { f('u'); 4 }
287287
_ { f('U'); 8 }
288288
);
289-
do i32::range_step(4 * (pad - 1), -1, -4) |offset| {
289+
for offset in range_step::<i32>(4 * (pad - 1), -1, -4) {
290290
unsafe {
291291
match ((c as i32) >> offset) & 0xf {
292292
i @ 0 .. 9 => { f(transmute('0' as i32 + i)); }
293293
i => { f(transmute('a' as i32 + (i - 10))); }
294294
}
295295
}
296-
true
297-
};
296+
}
298297
}
299298

300299
///

src/libstd/rand.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use clone::Clone;
4848
use cmp;
4949
use container::Container;
5050
use int;
51-
use iter::{Iterator, range};
51+
use iter::{Iterator, range, range_step};
5252
use local_data;
5353
use num;
5454
use prelude::*;
@@ -748,7 +748,7 @@ impl IsaacRng {
748748
if use_rsl {
749749
macro_rules! memloop (
750750
($arr:expr) => {{
751-
do u32::range_step(0, RAND_SIZE, 8) |i| {
751+
for i in range_step(0u32, RAND_SIZE, 8) {
752752
a+=$arr[i ]; b+=$arr[i+1];
753753
c+=$arr[i+2]; d+=$arr[i+3];
754754
e+=$arr[i+4]; f+=$arr[i+5];
@@ -758,22 +758,20 @@ impl IsaacRng {
758758
self.mem[i+2]=c; self.mem[i+3]=d;
759759
self.mem[i+4]=e; self.mem[i+5]=f;
760760
self.mem[i+6]=g; self.mem[i+7]=h;
761-
true
762-
};
761+
}
763762
}}
764763
);
765764

766765
memloop!(self.rsl);
767766
memloop!(self.mem);
768767
} else {
769-
do u32::range_step(0, RAND_SIZE, 8) |i| {
768+
for i in range_step(0u32, RAND_SIZE, 8) {
770769
mix!();
771770
self.mem[i ]=a; self.mem[i+1]=b;
772771
self.mem[i+2]=c; self.mem[i+3]=d;
773772
self.mem[i+4]=e; self.mem[i+5]=f;
774773
self.mem[i+6]=g; self.mem[i+7]=h;
775-
true
776-
};
774+
}
777775
}
778776

779777
self.isaac();
@@ -794,7 +792,7 @@ impl IsaacRng {
794792
});
795793
macro_rules! rngstep(
796794
($j:expr, $shift:expr) => {{
797-
let base = base + $j;
795+
let base = $j;
798796
let mix = if $shift < 0 {
799797
a >> -$shift as uint
800798
} else {
@@ -813,13 +811,12 @@ impl IsaacRng {
813811

814812
let r = [(0, MIDPOINT), (MIDPOINT, 0)];
815813
for &(mr_offset, m2_offset) in r.iter() {
816-
do uint::range_step(0, MIDPOINT, 4) |base| {
817-
rngstep!(0, 13);
818-
rngstep!(1, -6);
819-
rngstep!(2, 2);
820-
rngstep!(3, -16);
821-
true
822-
};
814+
for i in range_step(0u, MIDPOINT, 4) {
815+
rngstep!(i + 0, 13);
816+
rngstep!(i + 1, -6);
817+
rngstep!(i + 2, 2);
818+
rngstep!(i + 3, -16);
819+
}
823820
}
824821

825822
self.a = a;

src/libstd/trie.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ pub fn check_integrity<T>(trie: &TrieNode<T>) {
520520
mod test_map {
521521
use super::*;
522522
use prelude::*;
523+
use iter::range_step;
523524
use uint;
524525

525526
#[test]
@@ -538,41 +539,37 @@ mod test_map {
538539
#[test]
539540
fn test_step() {
540541
let mut trie = TrieMap::new();
541-
let n = 300;
542+
let n = 300u;
542543

543-
do uint::range_step(1, n, 2) |x| {
544+
for x in range_step(1u, n, 2) {
544545
assert!(trie.insert(x, x + 1));
545546
assert!(trie.contains_key(&x));
546547
check_integrity(&trie.root);
547-
true
548-
};
548+
}
549549

550-
do uint::range_step(0, n, 2) |x| {
550+
for x in range_step(0u, n, 2) {
551551
assert!(!trie.contains_key(&x));
552552
assert!(trie.insert(x, x + 1));
553553
check_integrity(&trie.root);
554-
true
555-
};
554+
}
556555

557556
for x in range(0u, n) {
558557
assert!(trie.contains_key(&x));
559558
assert!(!trie.insert(x, x + 1));
560559
check_integrity(&trie.root);
561560
}
562561

563-
do uint::range_step(1, n, 2) |x| {
562+
for x in range_step(1u, n, 2) {
564563
assert!(trie.remove(&x));
565564
assert!(!trie.contains_key(&x));
566565
check_integrity(&trie.root);
567-
true
568-
};
566+
}
569567

570-
do uint::range_step(0, n, 2) |x| {
568+
for x in range_step(0u, n, 2) {
571569
assert!(trie.contains_key(&x));
572570
assert!(!trie.insert(x, x + 1));
573571
check_integrity(&trie.root);
574-
true
575-
};
572+
}
576573
}
577574

578575
#[test]
@@ -715,11 +712,10 @@ mod test_map {
715712
let value = 42u;
716713

717714
let mut map : TrieMap<uint> = TrieMap::new();
718-
do uint::range_step(0u, last, step as int) |x| {
715+
for x in range_step(0u, last, step) {
719716
assert!(x % step == 0);
720717
map.insert(x, value);
721-
true
722-
};
718+
}
723719

724720
for i in range(0u, last - step) {
725721
let mut lb = map.lower_bound_iter(i);

src/test/run-pass/num-range-rev.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ fn int_range_rev(hi: int, lo: int, it: &fn(int) -> bool) -> bool {
2828
}
2929

3030
fn int_range_step(a: int, b: int, step: int, it: &fn(int) -> bool) -> bool {
31-
int::range_step(a, b, step, it)
31+
std::iter::range_step(a, b, step).advance(it)
3232
}
3333

3434
fn uint_range_step(a: uint, b: uint, step: int, it: &fn(uint) -> bool) -> bool {
35-
uint::range_step(a, b, step, it)
35+
std::iter::range_step(a, b, step).advance(it)
3636
}
3737

3838

src/test/run-pass/num-range.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ fn int_range(lo: int, hi: int, it: &fn(int) -> bool) -> bool {
2020
}
2121

2222
fn int_range_step(a: int, b: int, step: int, it: &fn(int) -> bool) -> bool {
23-
int::range_step(a, b, step, it)
23+
std::iter::range_step(a, b, step).advance(it)
2424
}
2525

2626
fn uint_range_step(a: uint, b: uint, s: int, it: &fn(uint) -> bool) -> bool {
27-
uint::range_step(a, b, s, it)
27+
std::iter::range_step(a, b, s).advance(it)
2828
}
2929

3030
pub fn main() {
@@ -98,35 +98,31 @@ pub fn main() {
9898

9999
// range_step_inclusive will never pass stop element, and may skip it.
100100
let mut saw21 = false;
101-
do uint::range_step_inclusive(0, 21, 4) |x| {
101+
for x in std::iter::range_step_inclusive(0, 21, 4) {
102102
assert!(x <= 21);
103103
if x == 21 { saw21 = true; }
104-
true
105-
};
104+
}
106105
assert!(!saw21);
107106
let mut saw21 = false;
108-
do int::range_step_inclusive(0, 21, 4) |x| {
107+
for x in std::iter::range_step_inclusive(0, 21, 4) {
109108
assert!(x <= 21);
110109
if x == 21 { saw21 = true; }
111-
true
112-
};
110+
}
113111
assert!(!saw21);
114112

115113
// range_step_inclusive will never pass stop element, but may visit it.
116114
let mut saw21 = false;
117-
do uint::range_step_inclusive(0, 21, 3) |x| {
115+
for x in std::iter::range_step_inclusive(0, 21, 3) {
118116
assert!(x <= 21);
119117
printfln!("saw: %u", x);
120118
if x == 21 { saw21 = true; }
121-
true
122-
};
119+
}
123120
assert!(saw21);
124121
let mut saw21 = false;
125-
do int::range_step_inclusive(0, 21, 3) |x| {
122+
for x in std::iter::range_step_inclusive(0, 21, 3) {
126123
assert!(x <= 21);
127124
if x == 21 { saw21 = true; }
128-
true
129-
};
125+
}
130126
assert!(saw21);
131127

132128
}

0 commit comments

Comments
 (0)