From 78cac8f9348b4a7ed8110b2b6ee80e2e5628e140 Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Tue, 31 Jan 2023 18:45:05 -0500 Subject: [PATCH] Reduce calculations during update cycle. --- helix-term/src/commands/typed.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index c70928312..d66496370 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1445,15 +1445,20 @@ pub(super) fn goto_line_number( } return Ok(()); } - let (view, doc) = current!(cx.editor); - let text = doc.text().slice(..); - let line = doc.selection(view.id).primary().cursor_line(text); - cx.editor.last_line_number.get_or_insert(line + 1); - let line = args[0].parse::()?; - goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line)); + cx.editor.last_line_number.get_or_insert_with(|| { + let (view, doc) = current!(cx.editor); + + let text = doc.text().slice(..); + let line = doc.selection(view.id).primary().cursor_line(text); + + line + 1 + }); + let (view, doc) = current!(cx.editor); + let line = args[0].parse::()?; view.ensure_cursor_in_view(doc, line); + goto_line_without_jumplist(cx.editor, NonZeroUsize::new(line)); } } Ok(())