on master help sign in
Reuse a cursor from the pool if available (fixes #202)
aebdef8Blaž Hrastnik
helix-core/src/syntax.rs+5−1
@@ -366,7 +366,11 @@ impl Syntax {
366 // prevents them from being moved. But both of these values are really just
366 // prevents them from being moved. But both of these values are really just
367 // pointers, so it's actually ok to move them.
367 // pointers, so it's actually ok to move them.
368
368
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+ });
370 let tree_ref = unsafe { mem::transmute::<_, &'static Tree>(self.tree()) };
374 let tree_ref = unsafe { mem::transmute::<_, &'static Tree>(self.tree()) };
371 let cursor_ref = unsafe { mem::transmute::<_, &'static mut QueryCursor>(&mut cursor) };
375 let cursor_ref = unsafe { mem::transmute::<_, &'static mut QueryCursor>(&mut cursor) };
372 let query_ref = unsafe { mem::transmute::<_, &'static Query>(&self.config.query) };
376 let query_ref = unsafe { mem::transmute::<_, &'static Query>(&self.config.query) };