on master help sign in
Reuse a cursor from the pool if available (fixes #202)
commitaebdef8257173b31df77ae02bb23ec2abfd07e5c authorBlaž Hrastnik <blaz@mxxn.io> dateThu 10 Jun 2021, 12:49 (5 years ago) parent6b3c9d8
1 file changed+5−1
helix-core/src/syntax.rs+5−1
helix-core/src/syntax.rs+5−1
@@ -366,7 +366,11 @@ impl Syntax {
366366 // prevents them from being moved. But both of these values are really just
367367 // pointers, so it's actually ok to move them.
368368
369− let mut cursor = QueryCursor::new(); // reuse a pool
369+ // reuse a cursor from the pool if possible
370+ let mut cursor = PARSER.with(|ts_parser| {
371+ let highlighter = &mut ts_parser.borrow_mut();
372+ highlighter.cursors.pop().unwrap_or_else(QueryCursor::new)
373+ });
370374 let tree_ref = unsafe { mem::transmute::<_, &'static Tree>(self.tree()) };
371375 let cursor_ref = unsafe { mem::transmute::<_, &'static mut QueryCursor>(&mut cursor) };
372376 let query_ref = unsafe { mem::transmute::<_, &'static Query>(&self.config.query) };