fn reserve_inner(&mut self, additional: usize) {
        let len = self.len();
        let kind = self.kind();

        // Always check `inline` first, because if the handle is using inline
        // data storage, all of the `Inner` struct fields will be gibberish.
        if kind == KIND_INLINE {
            let new_cap = len + additional;

            // Promote to a vector
            *self = Inner::from_slice(new_cap, self.as_ref(), PoolId::DEFAULT.pool_ref());
            return;
        }

        // Reserving involves abandoning the currently shared buffer and
        // allocating a new vector with the requested capacity.
        let new_cap = len + additional;

        if kind == KIND_VEC {
            let vec = self.shared_vec();

            unsafe {
                let vec_cap = (*vec).cap - SHARED_VEC_SIZE;

                // First, try to reclaim the buffer. This is possible if the current
                // handle is the only outstanding handle pointing to the buffer.
                if (*vec).is_unique() && vec_cap >= new_cap {
                    // The capacity is sufficient, reclaim the buffer
                    let ptr = (vec as *mut u8).add(SHARED_VEC_SIZE);
                    ptr::copy(self.ptr, ptr, len);

                    self.ptr = ptr;
                    self.cap = vec_cap;
                } else {
                    // Create a new vector storage
                    *self = Inner::from_slice(new_cap, self.as_ref(), (*vec).pool);
                }
            }
        } else {
            debug_assert!(kind == KIND_ARC);

            let arc = self.arc.as_ptr();
            unsafe {
                // First, try to reclaim the buffer. This is possible if the current
                // handle is the only outstanding handle pointing to the buffer.
                if (*arc).is_unique() {
                    // This is the only handle to the buffer. It can be reclaimed.
                    // However, before doing the work of copying data, check to make
                    // sure that the vector has enough capacity.
                    let v = &mut (*arc).vec;

                    if v.capacity() >= new_cap {
                        // The capacity is sufficient, reclaim the buffer
                        let ptr = v.as_mut_ptr();

                        ptr::copy(self.ptr, ptr, len);

                        self.ptr = ptr;
                        self.cap = v.capacity();
                        return;
                    }
                }

                // Create a new vector storage
                *self = Inner::from_slice(new_cap, self.as_ref(), (*arc).pool);
            }
        }
    }
// In separate function to allow the short-circuits in `reserve` to
// be inline-able. Significant helps performance.
In separate function to allow the short-circuits in `reserve` to
be inline-able. Significant helps performance.
In separate function to allow the short - circuits in ` reserve ` to be inline - able . Significant helps performance .
fn reserve_inner(&mut self, additional: usize) {
        let len = self.len();
        let kind = self.kind();
        // Always check `inline` first, because if the handle is using inline
        // data storage, all of the `Inner` struct fields will be gibberish.
        if kind == KIND_INLINE {
            let new_cap = len + additional;
            // Promote to a vector
            *self = Inner::from_slice(new_cap, self.as_ref(), PoolId::DEFAULT.pool_ref());
            return;
        }
        // Reserving involves abandoning the currently shared buffer and
        // allocating a new vector with the requested capacity.
        let new_cap = len + additional;
        if kind == KIND_VEC {
            let vec = self.shared_vec();
            unsafe {
                let vec_cap = (*vec).cap - SHARED_VEC_SIZE;
                // First, try to reclaim the buffer. This is possible if the current
                // handle is the only outstanding handle pointing to the buffer.
                if (*vec).is_unique() && vec_cap >= new_cap {
                    // The capacity is sufficient, reclaim the buffer
                    let ptr = (vec as *mut u8).add(SHARED_VEC_SIZE);
                    ptr::copy(self.ptr, ptr, len);
                    self.ptr = ptr;
                    self.cap = vec_cap;
                } else {
                    // Create a new vector storage
                    *self = Inner::from_slice(new_cap, self.as_ref(), (*vec).pool);
                }
            }
        } else {
            debug_assert!(kind == KIND_ARC);
            let arc = self.arc.as_ptr();
            unsafe {
                // First, try to reclaim the buffer. This is possible if the current
                // handle is the only outstanding handle pointing to the buffer.
                if (*arc).is_unique() {
                    // This is the only handle to the buffer. It can be reclaimed.
                    // However, before doing the work of copying data, check to make
                    // sure that the vector has enough capacity.
                    let v = &mut (*arc).vec;
                    if v.capacity() >= new_cap {
                        // The capacity is sufficient, reclaim the buffer
                        let ptr = v.as_mut_ptr();
                        ptr::copy(self.ptr, ptr, len);
                        self.ptr = ptr;
                        self.cap = v.capacity();
                        return;
                    }
                }
                // Create a new vector storage
                *self = Inner::from_slice(new_cap, self.as_ref(), (*arc).pool);
            }
        }
    }
fn reserve_inner ( & mut self , additional : usize ) { let len = self . len ( ) ; let kind = self . kind ( ) ; // Always check `inline` first, because if the handle is using inline // data storage, all of the `Inner` struct fields will be gibberish. if kind == KIND_INLINE { let new_cap = len + additional ; // Promote to a vector * self = Inner :: from_slice ( new_cap , self . as_ref ( ) , PoolId :: DEFAULT . pool_ref ( ) ) ; return ; } // Reserving involves abandoning the currently shared buffer and // allocating a new vector with the requested capacity. let new_cap = len + additional ; if kind == KIND_VEC { let vec = self . shared_vec ( ) ; unsafe { let vec_cap = ( * vec ) . cap - SHARED_VEC_SIZE ; // First, try to reclaim the buffer. This is possible if the current // handle is the only outstanding handle pointing to the buffer. if ( * vec ) . is_unique ( ) && vec_cap >= new_cap { // The capacity is sufficient, reclaim the buffer let ptr = ( vec as * mut u8 ) . add ( SHARED_VEC_SIZE ) ; ptr :: copy ( self . ptr , ptr , len ) ; self . ptr = ptr ; self . cap = vec_cap ; } else { // Create a new vector storage * self = Inner :: from_slice ( new_cap , self . as_ref ( ) , ( * vec ) . pool ) ; } } } else { debug_assert ! ( kind KIND_ARC ) ; let arc = self . arc . as_ptr ( ) ; unsafe { // First, try to reclaim the buffer. This is possible if the current // handle is the only outstanding handle pointing to the buffer. if ( * arc ) . is_unique ( ) { // This is the only handle to the buffer. It can be reclaimed. // However, before doing the work of copying data, check to make // sure that the vector has enough capacity. let v = & mut ( * arc ) . vec ; if v . capacity ( ) >= new_cap { // The capacity is sufficient, reclaim the buffer let ptr = v . as_mut_ptr ( ) ; ptr :: copy ( self . ptr , ptr , len ) ; self . ptr = ptr ; self . cap = v . capacity ( ) ; return ; } } // Create a new vector storage * self = Inner :: from_slice ( new_cap , self . as_ref ( ) , ( * arc ) . pool ) ; } } }
In separate function to allow the short-circuits in `reserve` to
be inline-able.
In separate function to allow the short - circuits in ` reserve ` to be inline - able .
&mut self
additional
usize
&mut self
additional
usize