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 @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: 16e635cdfbb6b041886d1bccd28fa5e7e34c9f47
8
+ refs/heads/try2: ac64db94bf1d009a43e7f3729434417bd2e59662
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
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