pub fn fix_crlf_seam(&mut self, byte_pos: Count, must_be_boundary: bool) {
        if let Node::Internal(ref mut children) = *self {
            if byte_pos == 0 {
                // Special-case 1
                Arc::make_mut(&mut children.nodes_mut()[0])
                    .fix_crlf_seam(byte_pos, must_be_boundary);
            } else if byte_pos == children.combined_info().bytes {
                // Special-case 2
                let (info, nodes) = children.data_mut();
                Arc::make_mut(nodes.last_mut().unwrap())
                    .fix_crlf_seam(info.last().unwrap().bytes, must_be_boundary);
            } else {
                // Find the child to navigate into
                let (child_i, start_info) = children.search_byte_idx(byte_pos as usize);
                let start_byte = start_info.bytes;

                let pos_in_child = byte_pos - start_byte;
                let child_len = children.info()[child_i].bytes;

                if pos_in_child == 0 || pos_in_child == child_len {
                    // Left or right edge, get neighbor and fix seam
                    let l_child_i = if pos_in_child == 0 {
                        debug_assert!(child_i != 0);
                        child_i - 1
                    } else {
                        debug_assert!(child_i < children.len());
                        child_i
                    };

                    // Scope for borrow
                    {
                        // Fetch the two children
                        let (mut l_child, mut r_child) =
                            children.get_two_mut(l_child_i, l_child_i + 1);
                        let l_child_bytes = l_child.0.bytes;
                        let l_child = Arc::make_mut(&mut l_child.1);
                        let r_child = Arc::make_mut(&mut r_child.1);

                        // Get the text of the two children and fix
                        // the seam between them.
                        // Scope for borrow.
                        {
                            let (l_text, l_offset) =
                                l_child.get_chunk_at_byte_mut(l_child_bytes as usize);
                            let (r_text, r_offset) = r_child.get_chunk_at_byte_mut(0);
                            if must_be_boundary {
                                assert!(l_offset == 0 || l_offset == l_text.len());
                                assert!(r_offset == 0 || r_offset == r_text.len());
                            }
                            fix_segment_seam(l_text, r_text);
                        }

                        // Fix up the children's metadata after the change
                        // to their text.
                        l_child.fix_info_right();
                        r_child.fix_info_left();
                    }

                    // Fix up this node's metadata for those
                    // two children.
                    children.update_child_info(l_child_i);
                    children.update_child_info(l_child_i + 1);

                    // Remove the children if empty.
                    if children.info()[l_child_i + 1].bytes == 0 {
                        children.remove(l_child_i + 1);
                    } else if children.info()[l_child_i].bytes == 0 {
                        children.remove(l_child_i);
                    }
                } else {
                    // Internal to child
                    Arc::make_mut(&mut children.nodes_mut()[child_i])
                        .fix_crlf_seam(pos_in_child, must_be_boundary);

                    children.update_child_info(child_i);

                    if children.info()[child_i].bytes == 0 {
                        children.remove(child_i);
                    }
                }
            }
        }
    }
/// Checks to make sure that a boundary between leaf nodes (given as a byte
/// position in the rope) doesn't split a CRLF pair, and fixes it if it does.
///
/// If `must_be_boundary` is true, panics if the given byte position is
/// not on the boundary between two leaf nodes.
///
/// TODO: theoretically this can leave an internal node with fewer than
/// MIN_CHILDREN children, although it is exceedingly unlikely with any
/// remotely sane text.  In the mean time, right now no code actually
/// depends on there being at least MIN_CHILDREN in an internal node.
/// But this should nevertheless get addressed at some point.
/// Probably the most straight-forward way to address this is via the
/// `fix_info_*` methods below, but I'm not totally sure.
Checks to make sure that a boundary between leaf nodes (given as a byte
position in the rope) doesn't split a CRLF pair, and fixes it if it does.

If `must_be_boundary` is true, panics if the given byte position is
not on the boundary between two leaf nodes.

theoretically this can leave an internal node with fewer than
MIN_CHILDREN children, although it is exceedingly unlikely with any
remotely sane text.  In the mean time, right now no code actually
depends on there being at least MIN_CHILDREN in an internal node.
But this should nevertheless get addressed at some point.
Probably the most straight-forward way to address this is via the
`fix_info_*` methods below, but I'm not totally sure.
Checks to make sure that a boundary between leaf nodes ( given as a byte position in the rope ) doesn ' t split a CRLF pair and fixes it if it does . If ` must_be_boundary ` is true panics if the given byte position is not on the boundary between two leaf nodes . theoretically this can leave an internal node with fewer than MIN_CHILDREN children although it is exceedingly unlikely with any remotely sane text . In the mean time right now no code actually depends on there being at least MIN_CHILDREN in an internal node . But this should nevertheless get addressed at some point . Probably the most straight - forward way to address this is via the ` fix_info_ * ` methods below but I ' m not totally sure .
pub fn fix_crlf_seam(&mut self, byte_pos: Count, must_be_boundary: bool) {
        if let Node::Internal(ref mut children) = *self {
            if byte_pos == 0 {
                // Special-case 1
                Arc::make_mut(&mut children.nodes_mut()[0])
                    .fix_crlf_seam(byte_pos, must_be_boundary);
            } else if byte_pos == children.combined_info().bytes {
                // Special-case 2
                let (info, nodes) = children.data_mut();
                Arc::make_mut(nodes.last_mut().unwrap())
                    .fix_crlf_seam(info.last().unwrap().bytes, must_be_boundary);
            } else {
                // Find the child to navigate into
                let (child_i, start_info) = children.search_byte_idx(byte_pos as usize);
                let start_byte = start_info.bytes;
                let pos_in_child = byte_pos - start_byte;
                let child_len = children.info()[child_i].bytes;
                if pos_in_child == 0 || pos_in_child == child_len {
                    // Left or right edge, get neighbor and fix seam
                    let l_child_i = if pos_in_child == 0 {
                        debug_assert!(child_i != 0);
                        child_i - 1
                    } else {
                        debug_assert!(child_i < children.len());
                        child_i
                    };
                    // Scope for borrow
                    {
                        // Fetch the two children
                        let (mut l_child, mut r_child) =
                            children.get_two_mut(l_child_i, l_child_i + 1);
                        let l_child_bytes = l_child.0.bytes;
                        let l_child = Arc::make_mut(&mut l_child.1);
                        let r_child = Arc::make_mut(&mut r_child.1);
                        // Get the text of the two children and fix
                        // the seam between them.
                        // Scope for borrow.
                        {
                            let (l_text, l_offset) =
                                l_child.get_chunk_at_byte_mut(l_child_bytes as usize);
                            let (r_text, r_offset) = r_child.get_chunk_at_byte_mut(0);
                            if must_be_boundary {
                                assert!(l_offset == 0 || l_offset == l_text.len());
                                assert!(r_offset == 0 || r_offset == r_text.len());
                            }
                            fix_segment_seam(l_text, r_text);
                        }
                        // Fix up the children's metadata after the change
                        // to their text.
                        l_child.fix_info_right();
                        r_child.fix_info_left();
                    }
                    // Fix up this node's metadata for those
                    // two children.
                    children.update_child_info(l_child_i);
                    children.update_child_info(l_child_i + 1);
                    // Remove the children if empty.
                    if children.info()[l_child_i + 1].bytes == 0 {
                        children.remove(l_child_i + 1);
                    } else if children.info()[l_child_i].bytes == 0 {
                        children.remove(l_child_i);
                    }
                } else {
                    // Internal to child
                    Arc::make_mut(&mut children.nodes_mut()[child_i])
                        .fix_crlf_seam(pos_in_child, must_be_boundary);
                    children.update_child_info(child_i);
                    if children.info()[child_i].bytes == 0 {
                        children.remove(child_i);
                    }
                }
            }
        }
    }
pub fn fix_crlf_seam ( & mut self , byte_pos : Count , must_be_boundary : bool ) { if let Node :: Internal ( ref mut children ) = * self { if byte_pos == 0 { // Special-case 1 Arc :: make_mut ( & mut children . nodes_mut ( ) [ 0 ] ) . fix_crlf_seam ( byte_pos , must_be_boundary ) ; } else if byte_pos == children . combined_info ( ) . bytes { // Special-case 2 let ( info , nodes ) = children . data_mut ( ) ; Arc :: make_mut ( nodes . last_mut ( ) . unwrap ( ) ) . fix_crlf_seam ( info . last ( ) . unwrap ( ) . bytes , must_be_boundary ) ; } else { // Find the child to navigate into let ( child_i , start_info ) = children . search_byte_idx ( byte_pos as usize ) ; let start_byte = start_info . bytes ; let pos_in_child = byte_pos - start_byte ; let child_len = children . info ( ) [ child_i ] . bytes ; if pos_in_child == 0 || pos_in_child == child_len { // Left or right edge, get neighbor and fix seam let l_child_i = if pos_in_child == 0 { debug_assert ! ( child_i 0 ) ; child_i - 1 } else { debug_assert ! ( child_i children len ( ) ) ; child_i } ; // Scope for borrow { // Fetch the two children let ( mut l_child , mut r_child ) = children . get_two_mut ( l_child_i , l_child_i + 1 ) ; let l_child_bytes = l_child . 0 . bytes ; let l_child = Arc :: make_mut ( & mut l_child . 1 ) ; let r_child = Arc :: make_mut ( & mut r_child . 1 ) ; // Get the text of the two children and fix // the seam between them. // Scope for borrow. { let ( l_text , l_offset ) = l_child . get_chunk_at_byte_mut ( l_child_bytes as usize ) ; let ( r_text , r_offset ) = r_child . get_chunk_at_byte_mut ( 0 ) ; if must_be_boundary { assert ! ( l_offset 0 l_offset l_text len ( ) ) ; assert ! ( r_offset 0 r_offset r_text len ( ) ) ; } fix_segment_seam ( l_text , r_text ) ; } // Fix up the children's metadata after the change // to their text. l_child . fix_info_right ( ) ; r_child . fix_info_left ( ) ; } // Fix up this node's metadata for those // two children. children . update_child_info ( l_child_i ) ; children . update_child_info ( l_child_i + 1 ) ; // Remove the children if empty. if children . info ( ) [ l_child_i + 1 ] . bytes == 0 { children . remove ( l_child_i + 1 ) ; } else if children . info ( ) [ l_child_i ] . bytes == 0 { children . remove ( l_child_i ) ; } } else { // Internal to child Arc :: make_mut ( & mut children . nodes_mut ( ) [ child_i ] ) . fix_crlf_seam ( pos_in_child , must_be_boundary ) ; children . update_child_info ( child_i ) ; if children . info ( ) [ child_i ] . bytes == 0 { children . remove ( child_i ) ; } } } } }
Checks to make sure that a boundary between leaf nodes (given as a byte
position in the rope) doesn't split a CRLF pair, and fixes it if it does.
Checks to make sure that a boundary between leaf nodes ( given as a byte position in the rope ) doesn ' t split a CRLF pair and fixes it if it does .
&mut self
byte_pos
Count
must_be_boundary
bool