aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-01-12 22:28:29 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-01-12 22:28:29 -0800
commit7078c6cd1d0fd008946edb3b0a964b8e83a83bc1 (patch)
treefce1eaf590925d8b74bdef32e8d78dae04f1dd1e /src
parentfd9d1b1d4db611f4298b67bc550d43d7b14f89b2 (diff)
downloadeditor-7078c6cd1d0fd008946edb3b0a964b8e83a83bc1.tar.zst
Remove unnecessary function from_slice.
Diffstat (limited to 'src')
-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;