/// Perform the one-by-one comparison and insertion.
Perform the one-by-one comparison and insertion.
Perform the one - by - one comparison and insertion .
fn merge(mut self) -> Result<(), E> {
        let is_greater = &self.is_greater;
        let mut first_count: usize = 0;
        let mut second_count: usize = 0;
        while self.first_pos < self.dest_pos && self.first_pos >= 0 {
            debug_assert!(self.first_pos + self.second_pos + 1 == self.dest_pos);
            if (second_count | first_count) < MIN_GALLOP {
                // One-at-a-time mode.
                unsafe {
                    if is_greater(
                        self.list.get_unchecked(self.first_pos as usize),
                        self.tmp.get_unchecked(self.second_pos as usize),
                    )? {
                        ptr::copy_nonoverlapping(
                            self.list.get_unchecked(self.first_pos as usize),
                            self.list.get_unchecked_mut(self.dest_pos as usize),
                            1,
                        );
                        self.first_pos -= 1;
                    } else {
                        ptr::copy_nonoverlapping(
                            md_as_inner(&self.tmp).get_unchecked(self.second_pos as usize),
                            self.list.get_unchecked_mut(self.dest_pos as usize),
                            1,
                        );
                        self.second_pos -= 1;
                    }
                }
                self.dest_pos -= 1;
            } else {
                // Galloping mode.
                first_count = self.first_pos as usize + 1
                    - gallop_right(
                        unsafe { md_as_inner(&self.tmp).get_unchecked(self.second_pos as usize) },
                        &self.list[..=self.first_pos as usize],
                        gallop::Mode::Reverse,
                        is_greater,
                    )?;
                unsafe {
                    copy_backwards(
                        self.list.get_unchecked(self.first_pos as usize),
                        self.list.get_unchecked_mut(self.dest_pos as usize),
                        first_count,
                    )
                }
                self.dest_pos -= first_count as isize;
                self.first_pos -= first_count as isize;
                debug_assert!(self.first_pos + self.second_pos + 1 == self.dest_pos);
                if self.first_pos < self.dest_pos && self.first_pos >= 0 {
                    second_count = self.second_pos as usize + 1
                        - gallop_left(
                            unsafe { self.list.get_unchecked(self.first_pos as usize) },
                            md_as_inner(&self.tmp[..=self.second_pos as usize]),
                            gallop::Mode::Reverse,
                            is_greater,
                        )?;
                    unsafe {
                        copy_nonoverlapping_backwards(
                            md_as_inner(&self.tmp).get_unchecked(self.second_pos as usize),
                            self.list.get_unchecked_mut(self.dest_pos as usize),
                            second_count,
                        )
                    }
                    self.dest_pos -= second_count as isize;
                    self.second_pos -= second_count as isize;
                }
            }
        }
        Ok(())
    }
fn merge ( mut self ) -> Result < ( ) , E > { let is_greater = & self . is_greater ; let mut first_count : usize = 0 ; let mut second_count : usize = 0 ; while self . first_pos < self . dest_pos && self . first_pos >= 0 { debug_assert ! ( self first_pos self second_pos 1 self dest_pos ) ; if ( second_count | first_count ) < MIN_GALLOP { // One-at-a-time mode. unsafe { if is_greater ( self . list . get_unchecked ( self . first_pos as usize ) , self . tmp . get_unchecked ( self . second_pos as usize ) , ) ? { ptr :: copy_nonoverlapping ( self . list . get_unchecked ( self . first_pos as usize ) , self . list . get_unchecked_mut ( self . dest_pos as usize ) , 1 , ) ; self . first_pos -= 1 ; } else { ptr :: copy_nonoverlapping ( md_as_inner ( & self . tmp ) . get_unchecked ( self . second_pos as usize ) , self . list . get_unchecked_mut ( self . dest_pos as usize ) , 1 , ) ; self . second_pos -= 1 ; } } self . dest_pos -= 1 ; } else { // Galloping mode. first_count = self . first_pos as usize + 1 - gallop_right ( unsafe { md_as_inner ( & self . tmp ) . get_unchecked ( self . second_pos as usize ) } , & self . list [ .. = self . first_pos as usize ] , gallop :: Mode :: Reverse , is_greater , ) ? ; unsafe { copy_backwards ( self . list . get_unchecked ( self . first_pos as usize ) , self . list . get_unchecked_mut ( self . dest_pos as usize ) , first_count , ) } self . dest_pos -= first_count as isize ; self . first_pos -= first_count as isize ; debug_assert ! ( self first_pos self second_pos 1 self dest_pos ) ; if self . first_pos < self . dest_pos && self . first_pos >= 0 { second_count = self . second_pos as usize + 1 - gallop_left ( unsafe { self . list . get_unchecked ( self . first_pos as usize ) } , md_as_inner ( & self . tmp [ .. = self . second_pos as usize ] ) , gallop :: Mode :: Reverse , is_greater , ) ? ; unsafe { copy_nonoverlapping_backwards ( md_as_inner ( & self . tmp ) . get_unchecked ( self . second_pos as usize ) , self . list . get_unchecked_mut ( self . dest_pos as usize ) , second_count , ) } self . dest_pos -= second_count as isize ; self . second_pos -= second_count as isize ; } } } Ok ( ( ) ) }
Perform the one-by-one comparison and insertion.
Perform the one - by - one comparison and insertion .
mut self