From 7078c6cd1d0fd008946edb3b0a964b8e83a83bc1 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Fri, 12 Jan 2024 22:28:29 -0800 Subject: Remove unnecessary function from_slice. --- src/rope.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/rope.rs') diff --git a/src/rope.rs b/src/rope.rs index 56f53d0..c5378b0 100644 --- a/src/rope.rs +++ b/src/rope.rs @@ -65,29 +65,25 @@ impl Rope { })) } - fn from_slice(buf: Rc<[u8]>, start: usize, end: usize) -> Rope { - if buf.len() > MAX_NODE_SIZE || start > buf.len() || end > buf.len() || start > end { - panic!("Invalid leaf!"); + fn leaf(buf: Rc<[u8]>) -> Rope { + if buf.len() > MAX_NODE_SIZE { + panic!("buffer too long"); } let mut lines = 0; - for &b in buf[start..end].iter() { + for &b in buf.iter() { if b == b'\n' { lines += 1; } } + let n = buf.len(); Rope(Node::Leaf(Leaf { unsafe_buf: Some(buf), - start: u16::try_from(start).expect("buffer too long"), - end: u16::try_from(end).expect("buffer too long"), + start: 0, + end: u16::try_from(n).expect("buffer too long"), lines, })) } - fn leaf(buf: Rc<[u8]>) -> Rope { - let n = buf.len(); - Rope::from_slice(buf, 0, n) - } - fn branch(children: Rc<[Rope]>) -> Rope { let mut len = 0; let mut lines = 0; -- cgit v1.3.1