aboutsummaryrefslogtreecommitdiff
path: root/helix-view
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-view
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-view')
-rw-r--r--helix-view/src/document.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index b08370f9..af7e3a7e 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -642,7 +642,7 @@ impl Document {
) -> Self {
let (encoding, has_bom) = encoding_with_bom_info.unwrap_or((encoding::UTF_8, false));
let line_ending = config.load().default_line_ending.into();
- let changes = ChangeSet::new(&text);
+ let changes = ChangeSet::new(text.slice(..));
let old_state = None;
Self {
@@ -938,7 +938,7 @@ impl Document {
) -> Option<Arc<helix_core::syntax::LanguageConfiguration>> {
config_loader
.language_config_for_file_name(self.path.as_ref()?)
- .or_else(|| config_loader.language_config_for_shebang(self.text()))
+ .or_else(|| config_loader.language_config_for_shebang(self.text().slice(..)))
}
/// Detect the indentation used in the file, or otherwise defaults to the language indentation
@@ -1030,7 +1030,7 @@ impl Document {
) {
if let (Some(language_config), Some(loader)) = (language_config, loader) {
if let Some(highlight_config) = language_config.highlight_config(&loader.scopes()) {
- self.syntax = Syntax::new(&self.text, highlight_config, loader);
+ self.syntax = Syntax::new(self.text.slice(..), highlight_config, loader);
}
self.language = Some(language_config);
@@ -1165,7 +1165,11 @@ impl Document {
// update tree-sitter syntax tree
if let Some(syntax) = &mut self.syntax {
// TODO: no unwrap
- let res = syntax.update(&old_doc, &self.text, transaction.changes());
+ let res = syntax.update(
+ old_doc.slice(..),
+ self.text.slice(..),
+ transaction.changes(),
+ );
if res.is_err() {
log::error!("TS parser failed, disabeling TS for the current buffer: {res:?}");
self.syntax = None;
@@ -1288,7 +1292,7 @@ impl Document {
if success {
// reset changeset to fix len
- self.changes = ChangeSet::new(self.text());
+ self.changes = ChangeSet::new(self.text().slice(..));
// Sync with changes with the jumplist selections.
view.sync_changes(self);
}
@@ -1371,7 +1375,7 @@ impl Document {
}
if success {
// reset changeset to fix len
- self.changes = ChangeSet::new(self.text());
+ self.changes = ChangeSet::new(self.text().slice(..));
// Sync with changes with the jumplist selections.
view.sync_changes(self);
}
@@ -1394,7 +1398,7 @@ impl Document {
return;
}
- let new_changeset = ChangeSet::new(self.text());
+ let new_changeset = ChangeSet::new(self.text().slice(..));
let changes = std::mem::replace(&mut self.changes, new_changeset);
// Instead of doing this messy merge we could always commit, and based on transaction
// annotations either add a new layer or compose into the previous one.