Skip to content

Commit 1f3f1b8

Browse files
committed
perf: save a clone in the fn auto_pairs
1 parent 6829f54 commit 1f3f1b8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

helix-term/src/commands.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use helix_view::{
5858
};
5959

6060
use anyhow::{anyhow, bail, ensure, Context as _};
61+
use arc_swap::access::DynAccess;
6162
use insert::*;
6263
use movement::Movement;
6364

@@ -4152,7 +4153,9 @@ pub mod insert {
41524153
let (view, doc) = current_ref!(cx.editor);
41534154
let text = doc.text();
41544155
let selection = doc.selection(view.id);
4155-
let auto_pairs = doc.auto_pairs(cx.editor, view);
4156+
4157+
let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
4158+
let auto_pairs = doc.auto_pairs(cx.editor, loader, view);
41564159

41574160
let transaction = auto_pairs
41584161
.as_ref()
@@ -4320,11 +4323,12 @@ pub mod insert {
43204323
),
43214324
};
43224325

4326+
let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
43234327
// If we are between pairs (such as brackets), we want to
43244328
// insert an additional line which is indented one level
43254329
// more and place the cursor there
43264330
let on_auto_pair = doc
4327-
.auto_pairs(cx.editor, view)
4331+
.auto_pairs(cx.editor, loader, view)
43284332
.as_deref()
43294333
.and_then(|pairs| pairs.get(prev))
43304334
.is_some_and(|pair| pair.open == prev && pair.close == curr);
@@ -4414,8 +4418,8 @@ pub mod insert {
44144418
let tab_width = doc.tab_width();
44154419
let indent_width = doc.indent_width();
44164420

4417-
let auto_pairs = doc.auto_pairs(cx.editor, view);
4418-
let auto_pairs = auto_pairs.as_deref();
4421+
let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
4422+
let auto_pairs = doc.auto_pairs(cx.editor, loader, view);
44194423

44204424
let transaction =
44214425
Transaction::delete_by_selection(doc.text(), doc.selection(view.id), |range| {

helix-view/src/document.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,12 @@ impl Document {
21702170
/// language config with auto pairs configured, returns that;
21712171
/// otherwise, falls back to the global auto pairs config. If the global
21722172
/// config is false, then ignore language settings.
2173-
pub fn auto_pairs<'a>(&'a self, editor: &'a Editor, view: &View) -> Option<Cow<'a, AutoPairs>> {
2173+
pub fn auto_pairs<'a>(
2174+
&'a self,
2175+
editor: &'a Editor,
2176+
loader: &'a syntax::Loader,
2177+
view: &View,
2178+
) -> Option<&'a AutoPairs> {
21742179
let global_config = (editor.auto_pairs).as_ref();
21752180

21762181
// NOTE: If the user specifies the global auto pairs config as false, then
@@ -2189,11 +2194,10 @@ impl Document {
21892194
let (start, end) = selection.into_byte_range(self.text().slice(..));
21902195
let layer = syntax.layer_for_byte_range(start as u32, end as u32);
21912196

2192-
let loader: &syntax::Loader = &editor.syn_loader.load();
21932197
let lang_config = loader.language(syntax.layer(layer).language).config();
2194-
lang_config.auto_pairs.clone().map(Cow::Owned)
2198+
lang_config.auto_pairs.as_ref()
21952199
})
2196-
.or(global_config.map(Cow::Borrowed))
2200+
.or(global_config)
21972201
}
21982202

21992203
pub fn snippet_ctx(&self) -> SnippetRenderCtx {

0 commit comments

Comments
 (0)