File tree 2 files changed +7
-2
lines changed
2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -1504,7 +1504,9 @@ capacity, then no action is taken.
1504
1504
* n - The number of bytes to reserve space for
1505
1505
" ]
1506
1506
fn reserve ( & s: str , n : uint ) {
1507
- rustrt:: str_reserve_shared ( s, n) ;
1507
+ if capacity ( s) < n {
1508
+ rustrt:: str_reserve_shared ( s, n) ;
1509
+ }
1508
1510
}
1509
1511
1510
1512
#[ doc = "
Original file line number Diff line number Diff line change @@ -113,7 +113,10 @@ capacity, then no action is taken.
113
113
* n - The number of elements to reserve space for
114
114
" ]
115
115
fn reserve < T > ( & v: [ const T ] , n : uint ) {
116
- rustrt:: vec_reserve_shared ( sys:: get_type_desc :: < T > ( ) , v, n) ;
116
+ // Only make the (slow) call into the runtime if we have to
117
+ if capacity ( v) < n {
118
+ rustrt:: vec_reserve_shared ( sys:: get_type_desc :: < T > ( ) , v, n) ;
119
+ }
117
120
}
118
121
119
122
#[ doc = "
You can’t perform that action at this time.
0 commit comments