aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-06-10 03:49:34 +0000
committerBlaž Hrastnik2021-06-10 03:49:34 +0000
commitaebdef8257173b31df77ae02bb23ec2abfd07e5c (patch)
tree6b32935700325500c00636d418e90fe5fa974093 /helix-core
parent6b3c9d8ed37fd36f8be8c217ec2c71fb73de63e7 (diff)
Reuse a cursor from the pool if available (fixes #202)
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/syntax.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 24b4e1a3..b0f82ca1 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -366,7 +366,11 @@ impl Syntax {
// prevents them from being moved. But both of these values are really just
// pointers, so it's actually ok to move them.
- let mut cursor = QueryCursor::new(); // reuse a pool
+ // reuse a cursor from the pool if possible
+ let mut cursor = PARSER.with(|ts_parser| {
+ let highlighter = &mut ts_parser.borrow_mut();
+ highlighter.cursors.pop().unwrap_or_else(QueryCursor::new)
+ });
let tree_ref = unsafe { mem::transmute::<_, &'static Tree>(self.tree()) };
let cursor_ref = unsafe { mem::transmute::<_, &'static mut QueryCursor>(&mut cursor) };
let query_ref = unsafe { mem::transmute::<_, &'static Query>(&self.config.query) };