From 259678585c3410044683bf4d2619b2d024a04514 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 1 Dec 2021 13:08:20 +0900 Subject: ui: Optimize tree-sitter style lookups Tree sitter returns an index referring to the position of the scope in the scopes array. We can use that same index to avoid a hashmap lookup and instead store the styles in an array. This currently stores the styles in both a map and an array because the UI still uses hashmap lookups, but it's a reasonable tradeoff. --- helix-view/src/theme.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'helix-view/src/theme.rs') diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 757316bd..2366ff7d 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -78,8 +78,11 @@ impl Loader { #[derive(Clone, Debug)] pub struct Theme { - scopes: Vec, + // UI styles are stored in a HashMap styles: HashMap, + // tree-sitter highlight styles are stored in a Vec to optimize lookups + scopes: Vec, + highlights: Vec