@@ -235,13 +235,13 @@ impl<T, A: AllocRef> RawVec<T, A> {
235235 }
236236 }
237237
238- /// Ensures that the buffer contains at least enough space to hold
239- /// `used_capacity + needed_extra_capacity` elements. If it doesn't already have
240- /// enough capacity, will reallocate enough space plus comfortable slack
241- /// space to get amortized `O(1)` behavior. Will limit this behavior
242- /// if it would needlessly cause itself to panic.
238+ /// Ensures that the buffer contains at least enough space to hold `len +
239+ /// additional` elements. If it doesn't already have enough capacity, will
240+ /// reallocate enough space plus comfortable slack space to get amortized
241+ /// `O(1)` behavior. Will limit this behavior if it would needlessly cause
242+ /// itself to panic.
243243 ///
244- /// If `used_capacity ` exceeds `self.capacity()`, this may fail to actually allocate
244+ /// If `len ` exceeds `self.capacity()`, this may fail to actually allocate
245245 /// the requested space. This is not really unsafe, but the unsafe
246246 /// code *you* write that relies on the behavior of this function may break.
247247 ///
@@ -287,37 +287,32 @@ impl<T, A: AllocRef> RawVec<T, A> {
287287 /// # vector.push_all(&[1, 3, 5, 7, 9]);
288288 /// # }
289289 /// ```
290- pub fn reserve ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
291- match self . try_reserve ( used_capacity , needed_extra_capacity ) {
290+ pub fn reserve ( & mut self , len : usize , additional : usize ) {
291+ match self . try_reserve ( len , additional ) {
292292 Err ( CapacityOverflow ) => capacity_overflow ( ) ,
293293 Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
294294 Ok ( ( ) ) => { /* yay */ }
295295 }
296296 }
297297
298298 /// The same as `reserve`, but returns on errors instead of panicking or aborting.
299- pub fn try_reserve (
300- & mut self ,
301- used_capacity : usize ,
302- needed_extra_capacity : usize ,
303- ) -> Result < ( ) , TryReserveError > {
304- if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
305- self . grow_amortized ( used_capacity, needed_extra_capacity)
299+ pub fn try_reserve ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
300+ if self . needs_to_grow ( len, additional) {
301+ self . grow_amortized ( len, additional)
306302 } else {
307303 Ok ( ( ) )
308304 }
309305 }
310306
311- /// Ensures that the buffer contains at least enough space to hold
312- /// `used_capacity + needed_extra_capacity` elements. If it doesn't already,
313- /// will reallocate the minimum possible amount of memory necessary.
314- /// Generally this will be exactly the amount of memory necessary,
315- /// but in principle the allocator is free to give back more than what
316- /// we asked for.
307+ /// Ensures that the buffer contains at least enough space to hold `len +
308+ /// additional` elements. If it doesn't already, will reallocate the
309+ /// minimum possible amount of memory necessary. Generally this will be
310+ /// exactly the amount of memory necessary, but in principle the allocator
311+ /// is free to give back more than we asked for.
317312 ///
318- /// If `used_capacity ` exceeds `self.capacity()`, this may fail to actually allocate
319- /// the requested space. This is not really unsafe, but the unsafe
320- /// code *you* write that relies on the behavior of this function may break.
313+ /// If `len ` exceeds `self.capacity()`, this may fail to actually allocate
314+ /// the requested space. This is not really unsafe, but the unsafe code
315+ /// *you* write that relies on the behavior of this function may break.
321316 ///
322317 /// # Panics
323318 ///
@@ -328,8 +323,8 @@ impl<T, A: AllocRef> RawVec<T, A> {
328323 /// # Aborts
329324 ///
330325 /// Aborts on OOM.
331- pub fn reserve_exact ( & mut self , used_capacity : usize , needed_extra_capacity : usize ) {
332- match self . try_reserve_exact ( used_capacity , needed_extra_capacity ) {
326+ pub fn reserve_exact ( & mut self , len : usize , additional : usize ) {
327+ match self . try_reserve_exact ( len , additional ) {
333328 Err ( CapacityOverflow ) => capacity_overflow ( ) ,
334329 Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
335330 Ok ( ( ) ) => { /* yay */ }
@@ -339,14 +334,10 @@ impl<T, A: AllocRef> RawVec<T, A> {
339334 /// The same as `reserve_exact`, but returns on errors instead of panicking or aborting.
340335 pub fn try_reserve_exact (
341336 & mut self ,
342- used_capacity : usize ,
343- needed_extra_capacity : usize ,
337+ len : usize ,
338+ additional : usize ,
344339 ) -> Result < ( ) , TryReserveError > {
345- if self . needs_to_grow ( used_capacity, needed_extra_capacity) {
346- self . grow_exact ( used_capacity, needed_extra_capacity)
347- } else {
348- Ok ( ( ) )
349- }
340+ if self . needs_to_grow ( len, additional) { self . grow_exact ( len, additional) } else { Ok ( ( ) ) }
350341 }
351342
352343 /// Shrinks the allocation down to the specified amount. If the given amount
@@ -371,8 +362,8 @@ impl<T, A: AllocRef> RawVec<T, A> {
371362impl < T , A : AllocRef > RawVec < T , A > {
372363 /// Returns if the buffer needs to grow to fulfill the needed extra capacity.
373364 /// Mainly used to make inlining reserve-calls possible without inlining `grow`.
374- fn needs_to_grow ( & self , used_capacity : usize , needed_extra_capacity : usize ) -> bool {
375- needed_extra_capacity > self . capacity ( ) . wrapping_sub ( used_capacity )
365+ fn needs_to_grow ( & self , len : usize , additional : usize ) -> bool {
366+ additional > self . capacity ( ) . wrapping_sub ( len )
376367 }
377368
378369 fn capacity_from_bytes ( excess : usize ) -> usize {
@@ -392,22 +383,18 @@ impl<T, A: AllocRef> RawVec<T, A> {
392383 // so that all of the code that depends on `T` is within it, while as much
393384 // of the code that doesn't depend on `T` as possible is in functions that
394385 // are non-generic over `T`.
395- fn grow_amortized (
396- & mut self ,
397- used_capacity : usize ,
398- needed_extra_capacity : usize ,
399- ) -> Result < ( ) , TryReserveError > {
386+ fn grow_amortized ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
400387 // This is ensured by the calling contexts.
401- debug_assert ! ( needed_extra_capacity > 0 ) ;
388+ debug_assert ! ( additional > 0 ) ;
389+
402390 if mem:: size_of :: < T > ( ) == 0 {
403391 // Since we return a capacity of `usize::MAX` when `elem_size` is
404392 // 0, getting to here necessarily means the `RawVec` is overfull.
405393 return Err ( CapacityOverflow ) ;
406394 }
407395
408396 // Nothing we can really do about these checks, sadly.
409- let required_cap =
410- used_capacity. checked_add ( needed_extra_capacity) . ok_or ( CapacityOverflow ) ?;
397+ let required_cap = len. checked_add ( additional) . ok_or ( CapacityOverflow ) ?;
411398
412399 // This guarantees exponential growth. The doubling cannot overflow
413400 // because `cap <= isize::MAX` and the type of `cap` is `usize`.
@@ -440,18 +427,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
440427 // The constraints on this method are much the same as those on
441428 // `grow_amortized`, but this method is usually instantiated less often so
442429 // it's less critical.
443- fn grow_exact (
444- & mut self ,
445- used_capacity : usize ,
446- needed_extra_capacity : usize ,
447- ) -> Result < ( ) , TryReserveError > {
430+ fn grow_exact ( & mut self , len : usize , additional : usize ) -> Result < ( ) , TryReserveError > {
448431 if mem:: size_of :: < T > ( ) == 0 {
449432 // Since we return a capacity of `usize::MAX` when the type size is
450433 // 0, getting to here necessarily means the `RawVec` is overfull.
451434 return Err ( CapacityOverflow ) ;
452435 }
453436
454- let cap = used_capacity . checked_add ( needed_extra_capacity ) . ok_or ( CapacityOverflow ) ?;
437+ let cap = len . checked_add ( additional ) . ok_or ( CapacityOverflow ) ?;
455438 let new_layout = Layout :: array :: < T > ( cap) ;
456439
457440 // `finish_grow` is non-generic over `T`.
0 commit comments