Skip to content

Commit 6432599

Browse files
committed
stdlib: Use if/alt expressions in std::bitv
1 parent 90e6453 commit 6432599

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/lib/bitv.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ fn uint_bits() -> uint {
3232
}
3333

3434
fn create(uint nbits, bool init) -> t {
35-
auto elt;
36-
if (init) {
37-
elt = ~0u;
35+
auto elt = if (init) {
36+
~0u
3837
} else {
39-
elt = 0u;
40-
}
38+
0u
39+
};
4140

4241
auto storage = vec::init_elt_mut[uint](elt, nbits / uint_bits() + 1u);
4342
ret rec(storage = storage, nbits = nbits);
@@ -161,11 +160,11 @@ fn set(&t v, uint i, bool x) {
161160
auto b = i % bits;
162161
auto w0 = v.storage.(w);
163162
auto flag = 1u << b;
164-
if (x) {
165-
v.storage.(w) = v.storage.(w) | flag;
163+
v.storage.(w) = if (x) {
164+
v.storage.(w) | flag
166165
} else {
167-
v.storage.(w) = v.storage.(w) & ~flag;
168-
}
166+
v.storage.(w) & ~flag
167+
};
169168
}
170169

171170
/* true if all bits are 1 */
@@ -191,11 +190,11 @@ fn is_false(&t v) -> bool {
191190
}
192191

193192
fn init_to_vec(t v, uint i) -> uint {
194-
if (get(v, i)) {
195-
ret 1u;
193+
ret if (get(v, i)) {
194+
1u
196195
} else {
197-
ret 0u;
198-
}
196+
0u
197+
};
199198
}
200199

201200
fn to_vec(&t v) -> vec[uint] {

0 commit comments

Comments
 (0)