chore: reduce component overhead (#3)

Reviewed-on: reya/gpui-native-kit#3
This commit is contained in:
2026-11-09 10:09:56 +00:00
parent 6815585528
commit 1c091db699
44 changed files with 1376 additions and 1241 deletions
+5 -14
View File
@@ -67,17 +67,8 @@ pub struct HighlightedCode {
/// Highlights `source` with `language`'s tree-sitter grammar.
pub fn highlight(source: &str, language: Language) -> HighlightedCode {
highlight_with_tree(source, language, None).0
}
/// Highlights `source`, reusing `old_tree` so only the changed region is re-lexed.
pub fn highlight_with_tree(
source: &str,
language: Language,
old_tree: Option<&tree_sitter::Tree>,
) -> (HighlightedCode, Option<tree_sitter::Tree>) {
let Some((grammar, query_source)) = grammar_for(language) else {
return (plain(source), None);
return plain(source);
};
HIGHLIGHTERS.with(|cache| {
@@ -104,11 +95,11 @@ pub fn highlight_with_tree(
.as_mut();
let Some(highlighter) = highlighter else {
return (plain(source), None);
return plain(source);
};
let Some(tree) = highlighter.parser.parse(source, old_tree) else {
return (plain(source), None);
let Some(tree) = highlighter.parser.parse(source, None) else {
return plain(source);
};
// One role per byte; matches arrive in query order
@@ -134,7 +125,7 @@ pub fn highlight_with_tree(
}
}
(build_lines(source, &role_at), Some(tree))
build_lines(source, &role_at)
})
}