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