Skip to content

Commit f4b58b6

Browse files
committed
perf: save a clone in the fn auto_pairs
1 parent 2c23557 commit f4b58b6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-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, doc);
4156+
4157+
let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
4158+
let auto_pairs = doc.auto_pairs(cx.editor, loader, view, doc);
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, doc)
4331+
.auto_pairs(cx.editor, loader, view, doc)
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, doc);
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, doc);
44194423

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

helix-view/src/document.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,9 +2173,10 @@ impl Document {
21732173
pub fn auto_pairs<'a>(
21742174
&'a self,
21752175
editor: &'a Editor,
2176+
loader: &'a syntax::Loader,
21762177
view: &View,
21772178
doc: &Document,
2178-
) -> Option<Cow<'a, AutoPairs>> {
2179+
) -> Option<&'a AutoPairs> {
21792180
let global_config = (editor.auto_pairs).as_ref();
21802181

21812182
// NOTE: If the user specifies the global auto pairs config as false, then
@@ -2194,11 +2195,10 @@ impl Document {
21942195
let (start, end) = selection.into_byte_range(doc.text().slice(..));
21952196
let layer = syntax.layer_for_byte_range(start as u32, end as u32);
21962197

2197-
let loader: &syntax::Loader = &editor.syn_loader.load();
21982198
let lang_config = loader.language(syntax.layer(layer).language).config();
2199-
lang_config.auto_pairs.clone().map(Cow::Owned)
2199+
lang_config.auto_pairs.as_ref()
22002200
})
2201-
.or(global_config.map(Cow::Borrowed))
2201+
.or(global_config)
22022202
}
22032203

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

0 commit comments

Comments
 (0)