Skip to content

Commit 355826c

Browse files
committed
---
yaml --- r: 131544 b: refs/heads/dist-snap c: 7a7ae99 h: refs/heads/master v: v3
1 parent 0966e35 commit 355826c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: a698b81ebfe02a614f9b41e68c6b604597a81229
9+
refs/heads/dist-snap: 7a7ae993ce694bf75a11632b394916e055a4d8ec
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcollections/bitv.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,10 @@ impl BitvSet {
515515
/// Grows the vector to be able to store bits with indices `[0, size - 1]`
516516
fn grow(&mut self, size: uint) {
517517
let &BitvSet(ref mut bitv) = self;
518+
let old_size = bitv.storage.len();
518519
let size = (size + uint::BITS - 1) / uint::BITS;
519-
if bitv.storage.len() < size {
520-
bitv.storage.grow(size, &0);
520+
if old_size < size {
521+
bitv.storage.grow(size - old_size, &0);
521522
}
522523
}
523524

@@ -1253,14 +1254,22 @@ mod tests {
12531254

12541255
#[test]
12551256
fn test_bitv_set_basic() {
1257+
// calculate nbits with uint::BITS granularity
1258+
fn calc_nbits(bits: uint) -> uint {
1259+
uint::BITS * ((bits + uint::BITS - 1) / uint::BITS)
1260+
}
1261+
12561262
let mut b = BitvSet::new();
1263+
assert_eq!(b.capacity(), calc_nbits(0));
12571264
assert!(b.insert(3));
1265+
assert_eq!(b.capacity(), calc_nbits(3));
12581266
assert!(!b.insert(3));
12591267
assert!(b.contains(&3));
12601268
assert!(b.insert(4));
12611269
assert!(!b.insert(4));
12621270
assert!(b.contains(&3));
12631271
assert!(b.insert(400));
1272+
assert_eq!(b.capacity(), calc_nbits(400));
12641273
assert!(!b.insert(400));
12651274
assert!(b.contains(&400));
12661275
assert_eq!(b.len(), 3);

0 commit comments

Comments
 (0)