Skip to content

Commit 36bde3e

Browse files
committed
---
yaml --- r: 153124 b: refs/heads/try2 c: 7a7ae99 h: refs/heads/master v: v3
1 parent c02de10 commit 36bde3e

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a698b81ebfe02a614f9b41e68c6b604597a81229
8+
refs/heads/try2: 7a7ae993ce694bf75a11632b394916e055a4d8ec
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)