Skip to content

Commit 2e1d2ad

Browse files
author
blake2-ppc
committed
---
yaml --- r: 64039 b: refs/heads/snap-stage3 c: 0ff5c17 h: refs/heads/master i: 64037: 4493277 64035: e67bce0 64031: cb4bed2 v: v3
1 parent 7367d48 commit 2e1d2ad

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8a3267672c43e7cc116e588dd21998d14fc21ba4
4+
refs/heads/snap-stage3: 0ff5c17cbbef0aedfa2eb1142cbf7a87abfd1d05
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/deque.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use std::uint;
1414
use std::vec;
1515
use std::iterator::FromIterator;
1616

17-
static INITIAL_CAPACITY: uint = 32u; // 2^5
17+
static INITIAL_CAPACITY: uint = 8u; // 2^3
18+
static MINIMUM_CAPACITY: uint = 2u;
1819

1920
#[allow(missing_doc)]
2021
pub struct Deque<T> {
@@ -43,8 +44,13 @@ impl<T> Mutable for Deque<T> {
4344
impl<T> Deque<T> {
4445
/// Create an empty Deque
4546
pub fn new() -> Deque<T> {
47+
Deque::with_capacity(INITIAL_CAPACITY)
48+
}
49+
50+
/// Create an empty Deque with space for at least `n` elements.
51+
pub fn with_capacity(n: uint) -> Deque<T> {
4652
Deque{nelts: 0, lo: 0,
47-
elts: vec::from_fn(INITIAL_CAPACITY, |_| None)}
53+
elts: vec::from_fn(uint::max(MINIMUM_CAPACITY, n), |_| None)}
4854
}
4955

5056
/// Return a reference to the first element in the deque
@@ -527,6 +533,16 @@ mod tests {
527533

528534
}
529535

536+
#[test]
537+
fn test_with_capacity() {
538+
let mut d = Deque::with_capacity(0);
539+
d.add_back(1);
540+
assert_eq!(d.len(), 1);
541+
let mut d = Deque::with_capacity(50);
542+
d.add_back(1);
543+
assert_eq!(d.len(), 1);
544+
}
545+
530546
#[test]
531547
fn test_reserve() {
532548
let mut d = Deque::new();

0 commit comments

Comments
 (0)