@@ -211,13 +211,13 @@ impl<T, A: AllocRef> RawVec<T, A> {
211211 }
212212 }
213213
214- /// Ensures that the buffer contains at least enough space to hold
215- /// `used_capacity + needed_extra_capacity` elements. If it doesn't already have
216- /// enough capacity, will reallocate enough space plus comfortable slack
217- /// space to get amortized `O(1)` behavior. Will limit this behavior
218- /// if it would needlessly cause itself to panic.
214+ /// Ensures that the buffer contains at least enough space to hold `len +
215+ /// additional` elements. If it doesn't already have enough capacity, will
216+ /// reallocate enough space plus comfortable slack space to get amortized
217+ /// `O(1)` behavior. Will limit this behavior if it would needlessly cause
218+ /// itself to panic.
219219 ///
220- /// If `used_capacity ` exceeds `self.capacity()`, this may fail to actually allocate
220+ /// If `len ` exceeds `self.capacity()`, this may fail to actually allocate
221221 /// the requested space. This is not really unsafe, but the unsafe
222222 /// code *you* write that relies on the behavior of this function may break.
223223 ///
@@ -263,37 +263,32 @@ impl<T, A: AllocRef> RawVec<T, A> {
263263 /// # vector.push_all(&[1, 3, 5, 7, 9]);
264264 /// # }
265265 /// ```
266- pub fn reserve ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
267- match self . try_reserve ( used_capacity , needed_extra_capacity ) {
266+ pub fn reserve ( & mut self , len : usize , additional : usize ) {
267+ match self . try_reserve ( len , additional ) {
268268 Err ( CapacityOverflow ) => capacity_overflow ( ) ,
269269 Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
270270 Ok ( ( ) ) => { /* yay */ }
271271 }
272272 }
273273
274274 /// The same as `reserve`, but returns on errors instead of panicking or aborting.
275- pub fn try_reserve (
276- & mut self ,
277- used_capacity : usize ,
278- needed_extra_capacity : usize ,
279- ) -> Result < ( ) , TryReserveError > {
280- if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
281- self . grow_amortized ( used_capacity, needed_extra_capacity)
275+ pub fn try_reserve ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
276+ if self . needs_to_grow ( len, additional) {
277+ self . grow_amortized ( len, additional)
282278 } else {
283279 Ok ( ( ) )
284280 }
285281 }
286282
287- /// Ensures that the buffer contains at least enough space to hold
288- /// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
289- /// will reallocate the minimum possible amount of memory necessary.
290- /// Generally this will be exactly the amount of memory necessary,
291- /// but in principle the allocator is free to give back more than what
292- /// we asked for.
283+ /// Ensures that the buffer contains at least enough space to hold `len +
284+ /// additional` elements. If it doesn't already, will reallocate the
285+ /// minimum possible amount of memory necessary. Generally this will be
286+ /// exactly the amount of memory necessary, but in principle the allocator
287+ /// is free to give back more than we asked for.
293288 ///
294- /// If `used_capacity ` exceeds `self.capacity()`, this may fail to actually allocate
295- /// the requested space. This is not really unsafe, but the unsafe
296- /// code *you* write that relies on the behavior of this function may break.
289+ /// If `len ` exceeds `self.capacity()`, this may fail to actually allocate
290+ /// the requested space. This is not really unsafe, but the unsafe code
291+ /// *you* write that relies on the behavior of this function may break.
297292 ///
298293 /// # Panics
299294 ///
@@ -304,8 +299,8 @@ impl<T, A: AllocRef> RawVec<T, A> {
304299 /// # Aborts
305300 ///
306301 /// Aborts on OOM.
307- pub fn reserve_exact ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
308- match self . try_reserve_exact ( used_capacity , needed_extra_capacity ) {
302+ pub fn reserve_exact ( & mut self , len : usize , additional : usize ) {
303+ match self . try_reserve_exact ( len , additional ) {
309304 Err ( CapacityOverflow ) => capacity_overflow ( ) ,
310305 Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
311306 Ok ( ( ) ) => { /* yay */ }
@@ -315,14 +310,10 @@ impl<T, A: AllocRef> RawVec<T, A> {
315310 /// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
316311 pub fn try_reserve_exact (
317312 & mut self ,
318- used_capacity : usize ,
319- needed_extra_capacity : usize ,
313+ len : usize ,
314+ additional : usize ,
320315 ) -> Result < ( ) , TryReserveError > {
321- if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
322- self . grow_exact ( used_capacity, needed_extra_capacity)
323- } else {
324- Ok ( ( ) )
325- }
316+ if self . needs_to_grow ( len, additional) { self . grow_exact ( len, additional) } else { Ok ( ( ) ) }
326317 }
327318
328319 /// Shrinks the allocation down to the specified amount. If the given amount
@@ -347,8 +338,8 @@ impl<T, A: AllocRef> RawVec<T, A> {
347338impl < T , A : AllocRef > RawVec < T , A > {
348339 /// Returns if the buffer needs to grow to fulfill the needed extra capacity.
349340 /// Mainly used to make inlining reserve-calls possible without inlining `grow`.
350- fn needs_to_grow ( & self , used_capacity : usize , needed_extra_capacity : usize ) -> bool {
351- needed_extra_capacity > self . capacity ( ) . wrapping_sub ( used_capacity )
341+ fn needs_to_grow ( & self , len : usize , additional : usize ) -> bool {
342+ additional > self . capacity ( ) . wrapping_sub ( len )
352343 }
353344
354345 fn capacity_from_bytes ( excess : usize ) -> usize {
@@ -368,22 +359,18 @@ impl<T, A: AllocRef> RawVec<T, A> {
368359 // so that all of the code that depends on `T` is within it, while as much
369360 // of the code that doesn't depend on `T` as possible is in functions that
370361 // are non-generic over `T`.
371- fn grow_amortized (
372- & mut self ,
373- used_capacity : usize ,
374- needed_extra_capacity : usize ,
375- ) -> Result < ( ) , TryReserveError > {
362+ fn grow_amortized ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
376363 // This is ensured by the calling contexts.
377- debug_assert ! ( needed_extra_capacity > 0 ) ;
364+ debug_assert ! ( additional > 0 ) ;
365+
378366 if mem:: size_of :: < T > ( ) == 0 {
379367 // Since we return a capacity of `usize::MAX` when `elem_size` is
380368 // 0, getting to here necessarily means the `RawVec` is overfull.
381369 return Err ( CapacityOverflow ) ;
382370 }
383371
384372 // Nothing we can really do about these checks, sadly.
385- let required_cap =
386- used_capacity. checked_add ( needed_extra_capacity) . ok_or ( CapacityOverflow ) ?;
373+ let required_cap = len. checked_add ( additional) . ok_or ( CapacityOverflow ) ?;
387374
388375 // This guarantees exponential growth. The doubling cannot overflow
389376 // because `cap <= isize::MAX` and the type of `cap` is `usize`.
@@ -416,18 +403,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
416403 // The constraints on this method are much the same as those on
417404 // `grow_amortized`, but this method is usually instantiated less often so
418405 // it's less critical.
419- fn grow_exact (
420- & mut self ,
421- used_capacity : usize ,
422- needed_extra_capacity : usize ,
423- ) -> Result < ( ) , TryReserveError > {
406+ fn grow_exact ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
424407 if mem:: size_of :: < T > ( ) == 0 {
425408 // Since we return a capacity of `usize::MAX` when the type size is
426409 // 0, getting to here necessarily means the `RawVec` is overfull.
427410 return Err ( CapacityOverflow ) ;
428411 }
429412
430- let cap = used_capacity . checked_add ( needed_extra_capacity ) . ok_or ( CapacityOverflow ) ?;
413+ let cap = len . checked_add ( additional ) . ok_or ( CapacityOverflow ) ?;
431414 let new_layout = Layout :: array :: < T > ( cap) ;
432415
433416 // `finish_grow` is non-generic over `T`.
0 commit comments