Skip to content

Commit

Permalink
feat: don't compute line start for annotations positions, it's costly…
Browse files Browse the repository at this point in the history
… for pretty much no gain
  • Loading branch information
poliorcetics committed Feb 22, 2023
1 parent f8c9ecd commit 9f4cfad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
5 changes: 1 addition & 4 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ impl Application {
if let Some(doc) = doc {
let lang_conf = doc.language_config();
let text = doc.text();
let text_slice = text.slice(..);

let mut diagnostic_annotations = BTreeMap::new();

Expand Down Expand Up @@ -811,9 +810,7 @@ impl Application {
};

if enabled_inline_diagnostics {
let char_idx = text_slice.line_to_char(diagnostic.range.start.line as usize);

*diagnostic_annotations.entry(char_idx).or_default() += diagnostic.message.trim().lines().count();
*diagnostic_annotations.entry(start).or_default() += diagnostic.message.trim().lines().count();
}

Some(Diagnostic {
Expand Down
13 changes: 4 additions & 9 deletions helix-view/src/document/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,8 @@ pub(super) fn apply_changes_to_diagnostic_annotations(
// See `None` case above
None | Some([]) => doc.diagnostic_annotations = Default::default(),
Some(line_annotations) => {
let doc_text = doc.text.slice(..);

let get_new_anchor_char_idx = |annot: &LineAnnotation| {
let new_char_idx = changes.map_pos(annot.anchor_char_idx, Assoc::After);
let line = doc_text.char_to_line(new_char_idx);
doc_text.line_to_char(line)
};
let map_pos =
|annot: &LineAnnotation| changes.map_pos(annot.anchor_char_idx, Assoc::After);

// The algorithm here does its best to modify in place to avoid reallocations as much as possible
//
Expand All @@ -163,7 +158,7 @@ pub(super) fn apply_changes_to_diagnostic_annotations(
// 4) If the last write position was not the last member of the current lines annotations, it means we
// merged some of them together so we update the saved line annotations.

let new_anchor_char_idx = get_new_anchor_char_idx(&line_annotations[0]);
let new_anchor_char_idx = map_pos(&line_annotations[0]);
line_annotations[0].anchor_char_idx = new_anchor_char_idx;

let mut previous_anchor_char_idx = new_anchor_char_idx;
Expand All @@ -172,7 +167,7 @@ pub(super) fn apply_changes_to_diagnostic_annotations(

for reading_index in 1..line_annotations.len() {
let annot = &mut line_annotations[reading_index];
let new_anchor_char_idx = get_new_anchor_char_idx(annot);
let new_anchor_char_idx = map_pos(annot);

if new_anchor_char_idx == previous_anchor_char_idx {
line_annotations[writing_index].height += annot.height;
Expand Down

0 comments on commit 9f4cfad

Please sign in to comment.