Skip to content

Commit 7d0d2af

Browse files
huonwalexcrichton
authored andcommitted
---
yaml --- r: 149531 b: refs/heads/try2 c: ac64db9 h: refs/heads/master i: 149529: 2830227 149527: 98c27cd v: v3
1 parent cb0c7a7 commit 7d0d2af

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
@@ -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: 16e635cdfbb6b041886d1bccd28fa5e7e34c9f47
8+
refs/heads/try2: ac64db94bf1d009a43e7f3729434417bd2e59662
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

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