aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/transaction.rs
diff options
context:
space:
mode:
authorMichael Davis2023-07-25 18:15:36 +0000
committerBlaž Hrastnik2023-07-27 02:50:19 +0000
commit98ef05d768d287fef2eb790e0a8a6e9a72832e00 (patch)
tree856fa79ea0924834f786a22a76ddfbe188301330 /helix-core/src/transaction.rs
parentf0b877e2588306882f71eaad45a3f3e604885a34 (diff)
Prefer RopeSlice to &Rope in helix_core::syntax
Pascal and I discussed this and we think it's generally better to take a 'RopeSlice' rather than a '&Rope'. The code block rendering function in the markdown component module is a good example for how this can be useful: we can remove an allocation of a rope and instead directly turn a '&str' into a 'RopeSlice' which is very cheap. A change to prefer 'RopeSlice' to '&Rope' whenever the rope isn't modified would be nice, but it would be a very large diff (around 500+ 500-). Starting off with just the syntax functions seems like a nice middle-ground, and we can remove a Rope allocation because of it. Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Diffstat (limited to 'helix-core/src/transaction.rs')
-rw-r--r--helix-core/src/transaction.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 9d2a3e5c..fec62578 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -1,3 +1,4 @@
+use ropey::RopeSlice;
use smallvec::SmallVec;
use crate::{Range, Rope, Selection, Tendril};
@@ -42,7 +43,7 @@ impl ChangeSet {
}
#[must_use]
- pub fn new(doc: &Rope) -> Self {
+ pub fn new(doc: RopeSlice) -> Self {
let len = doc.len_chars();
Self {
changes: Vec::new(),
@@ -485,7 +486,7 @@ impl Transaction {
/// Create a new, empty transaction.
pub fn new(doc: &Rope) -> Self {
Self {
- changes: ChangeSet::new(doc),
+ changes: ChangeSet::new(doc.slice(..)),
selection: None,
}
}
@@ -946,9 +947,9 @@ mod test {
#[test]
fn combine_with_empty() {
let empty = Rope::from("");
- let a = ChangeSet::new(&empty);
+ let a = ChangeSet::new(empty.slice(..));
- let mut b = ChangeSet::new(&empty);
+ let mut b = ChangeSet::new(empty.slice(..));
b.insert("a".into());
let changes = a.compose(b);
@@ -962,9 +963,9 @@ mod test {
const TEST_CASE: &str = "Hello, これはヘリックスエディターです!";
let empty = Rope::from("");
- let a = ChangeSet::new(&empty);
+ let a = ChangeSet::new(empty.slice(..));
- let mut b = ChangeSet::new(&empty);
+ let mut b = ChangeSet::new(empty.slice(..));
b.insert(TEST_CASE.into());
let changes = a.compose(b);