File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
5
- refs/heads/try: 16e635cdfbb6b041886d1bccd28fa5e7e34c9f47
5
+ refs/heads/try: ac64db94bf1d009a43e7f3729434417bd2e59662
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ use container::Container;
18
18
use iter:: { DoubleEndedIterator , FromIterator , Iterator } ;
19
19
use libc:: { free, c_void} ;
20
20
use mem:: { size_of, move_val_init} ;
21
+ use num;
21
22
use num:: CheckedMul ;
22
23
use ops:: Drop ;
23
24
use option:: { None , Option , Some } ;
@@ -136,6 +137,12 @@ impl<T> Vec<T> {
136
137
self . cap
137
138
}
138
139
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
+
139
146
pub fn reserve_exact ( & mut self , capacity : uint ) {
140
147
if capacity >= self . len {
141
148
let size = capacity. checked_mul ( & size_of :: < T > ( ) ) . expect ( "capacity overflow" ) ;
@@ -296,7 +303,7 @@ impl<T> Vec<T> {
296
303
let len = self . len ( ) ;
297
304
assert ! ( index <= len) ;
298
305
// space for the new element
299
- self . reserve_exact ( len + 1 ) ;
306
+ self . reserve ( len + 1 ) ;
300
307
301
308
unsafe { // infallible
302
309
// The spot to put the new value
You can’t perform that action at this time.
0 commit comments