aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/rope.rs18
1 files changed, 7 insertions, 11 deletions
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;