unsafe fn insert_node_at(&mut self, cursor: &mut RopeCursor, contents: &str, num_chars: usize, update_cursor: bool) {
        // println!("Insert_node_at {} len {}", contents.len(), self.num_bytes);
        // assert!(contents.len() < NODE_STR_SIZE);
        debug_assert_eq!(count_chars(contents), num_chars);
        debug_assert!(num_chars <= NODE_STR_SIZE);

        // TODO: Pin this sucka.
        // let new_node = Pin::new(Node::alloc());
        let new_node = Node::alloc(&mut self.rng, contents);
        // (*new_node).num_bytes = contents.len() as u8;
        // (*new_node).str[..contents.len()].copy_from_slice(contents.as_bytes());

        let new_height = (*new_node).height as usize;

        let mut head_height = self.head.height as usize;
        while head_height <= new_height {
            // TODO: Why do we copy here? Explain it in a comment. This is
            // currently lifted from the C code.
            self.nexts[head_height] = self.nexts[head_height - 1];
            cursor.0[head_height] = cursor.0[head_height - 1];

            self.head.height += 1; // Ends up 1 more than the max node height.
            head_height += 1;
        }

        for i in 0..new_height {
            let prev_skip = &mut (*cursor.0[i].node).nexts_mut()[i];
            let nexts = (*new_node).nexts_mut();
            nexts[i].node = prev_skip.node;
            nexts[i].skip_chars = num_chars + prev_skip.skip_chars - cursor.0[i].skip_chars;

            prev_skip.node = new_node;
            prev_skip.skip_chars = cursor.0[i].skip_chars;

            // & move the iterator to the end of the newly inserted node.
            if update_cursor {
                cursor.0[i].node = new_node;
                cursor.0[i].skip_chars = num_chars;
            }
        }

        for i in new_height..head_height {
            (*cursor.0[i].node).nexts_mut()[i].skip_chars += num_chars;
            if update_cursor {
                cursor.0[i].skip_chars += num_chars;
            }
        }

        // self.nexts[self.head.height as usize - 1].skip_chars += num_chars;
        self.num_bytes += contents.len();
    }
// Internal fn to create a new node at the specified iterator filled with the specified
// content.
Internal fn to create a new node at the specified iterator filled with the specified
content.
Internal fn to create a new node at the specified iterator filled with the specified content .
unsafe fn insert_node_at(&mut self, cursor: &mut RopeCursor, contents: &str, num_chars: usize, update_cursor: bool) {
        // println!("Insert_node_at {} len {}", contents.len(), self.num_bytes);
        // assert!(contents.len() < NODE_STR_SIZE);
        debug_assert_eq!(count_chars(contents), num_chars);
        debug_assert!(num_chars <= NODE_STR_SIZE);
        // TODO: Pin this sucka.
        // let new_node = Pin::new(Node::alloc());
        let new_node = Node::alloc(&mut self.rng, contents);
        // (*new_node).num_bytes = contents.len() as u8;
        // (*new_node).str[..contents.len()].copy_from_slice(contents.as_bytes());
        let new_height = (*new_node).height as usize;
        let mut head_height = self.head.height as usize;
        while head_height <= new_height {
            // TODO: Why do we copy here? Explain it in a comment. This is
            // currently lifted from the C code.
            self.nexts[head_height] = self.nexts[head_height - 1];
            cursor.0[head_height] = cursor.0[head_height - 1];
            self.head.height += 1; // Ends up 1 more than the max node height.
            head_height += 1;
        }
        for i in 0..new_height {
            let prev_skip = &mut (*cursor.0[i].node).nexts_mut()[i];
            let nexts = (*new_node).nexts_mut();
            nexts[i].node = prev_skip.node;
            nexts[i].skip_chars = num_chars + prev_skip.skip_chars - cursor.0[i].skip_chars;
            prev_skip.node = new_node;
            prev_skip.skip_chars = cursor.0[i].skip_chars;
            // & move the iterator to the end of the newly inserted node.
            if update_cursor {
                cursor.0[i].node = new_node;
                cursor.0[i].skip_chars = num_chars;
            }
        }
        for i in new_height..head_height {
            (*cursor.0[i].node).nexts_mut()[i].skip_chars += num_chars;
            if update_cursor {
                cursor.0[i].skip_chars += num_chars;
            }
        }
        // self.nexts[self.head.height as usize - 1].skip_chars += num_chars;
        self.num_bytes += contents.len();
    }
unsafe fn insert_node_at ( & mut self , cursor : & mut RopeCursor , contents : & str , num_chars : usize , update_cursor : bool ) { // println!("Insert_node_at {} len {}", contents.len(), self.num_bytes); // assert!(contents.len() < NODE_STR_SIZE); debug_assert_eq ! ( count_chars ( contents ) num_chars ) ; debug_assert ! ( num_chars NODE_STR_SIZE ) ; // TODO: Pin this sucka. // let new_node = Pin::new(Node::alloc()); let new_node = Node :: alloc ( & mut self . rng , contents ) ; // (*new_node).num_bytes = contents.len() as u8; // (*new_node).str[..contents.len()].copy_from_slice(contents.as_bytes()); let new_height = ( * new_node ) . height as usize ; let mut head_height = self . head . height as usize ; while head_height <= new_height { // TODO: Why do we copy here? Explain it in a comment. This is // currently lifted from the C code. self . nexts [ head_height ] = self . nexts [ head_height - 1 ] ; cursor . 0 [ head_height ] = cursor . 0 [ head_height - 1 ] ; self . head . height += 1 ; // Ends up 1 more than the max node height. head_height += 1 ; } for i in 0 .. new_height { let prev_skip = & mut ( * cursor . 0 [ i ] . node ) . nexts_mut ( ) [ i ] ; let nexts = ( * new_node ) . nexts_mut ( ) ; nexts [ i ] . node = prev_skip . node ; nexts [ i ] . skip_chars = num_chars + prev_skip . skip_chars - cursor . 0 [ i ] . skip_chars ; prev_skip . node = new_node ; prev_skip . skip_chars = cursor . 0 [ i ] . skip_chars ; // & move the iterator to the end of the newly inserted node. if update_cursor { cursor . 0 [ i ] . node = new_node ; cursor . 0 [ i ] . skip_chars = num_chars ; } } for i in new_height .. head_height { ( * cursor . 0 [ i ] . node ) . nexts_mut ( ) [ i ] . skip_chars += num_chars ; if update_cursor { cursor . 0 [ i ] . skip_chars += num_chars ; } } // self.nexts[self.head.height as usize - 1].skip_chars += num_chars; self . num_bytes += contents . len ( ) ; }
Internal fn to create a new node at the specified iterator filled with the specified
content.
Internal fn to create a new node at the specified iterator filled with the specified content .
&mut self
cursor
&mut RopeCursor
contents
&str
num_chars
usize
update_cursor
bool