Skip to content

Commit 13a5e1c

Browse files
huonwalexcrichton
authored andcommitted
---
yaml --- r: 104509 b: refs/heads/try c: ac64db9 h: refs/heads/master i: 104507: c9d0bde v: v3
1 parent e41ab39 commit 13a5e1c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
5-
refs/heads/try: 16e635cdfbb6b041886d1bccd28fa5e7e34c9f47
5+
refs/heads/try: ac64db94bf1d009a43e7f3729434417bd2e59662
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/vec_ng.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use container::Container;
1818
use iter::{DoubleEndedIterator, FromIterator, Iterator};
1919
use libc::{free, c_void};
2020
use mem::{size_of, move_val_init};
21+
use num;
2122
use num::CheckedMul;
2223
use ops::Drop;
2324
use option::{None, Option, Some};
@@ -136,6 +137,12 @@ impl<T> Vec<T> {
136137
self.cap
137138
}
138139

140+
pub fn reserve(&mut self, capacity: uint) {
141+
if capacity >= self.len {
142+
self.reserve_exact(num::next_power_of_two(capacity))
143+
}
144+
}
145+
139146
pub fn reserve_exact(&mut self, capacity: uint) {
140147
if capacity >= self.len {
141148
let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
@@ -296,7 +303,7 @@ impl<T> Vec<T> {
296303
let len = self.len();
297304
assert!(index <= len);
298305
// space for the new element
299-
self.reserve_exact(len + 1);
306+
self.reserve(len + 1);
300307

301308
unsafe { // infallible
302309
// The spot to put the new value

0 commit comments

Comments
 (0)