@@ -22,10 +22,10 @@ use anyhow::Error;
2222
2323pub use helix_core::diagnostic::Severity;
2424pub use helix_core::register::Registers;
25−use helix_core::{hashmap, syntax};
25+use helix_core::syntax;
2626use helix_core::{Position, Selection};
2727
28−use serde::Deserialize;
28+use serde::{Deserialize, Deserializer};
2929
3030fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error>
3131where
@@ -107,12 +107,28 @@ pub struct Config {
107107 pub cursor_shape: CursorShapeConfig,
108108}
109109
110−#[derive(Debug, Clone, PartialEq, Deserialize)]
111−#[serde(transparent)]
112−pub struct CursorShapeConfig(HashMap<Mode, CursorKind>);
110+// Cursor shape is read and used on every rendered frame and so needs
111+// to be fast. Therefore we avoid a hashmap and use an enum indexed array.
112+#[derive(Debug, Clone, PartialEq)]
113+pub struct CursorShapeConfig([CursorKind; 3]);
114+
115+impl<'de> Deserialize<'de> for CursorShapeConfig {
116+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
117+ where
118+ D: Deserializer<'de>,
119+ {
120+ let m = HashMap::<Mode, CursorKind>::deserialize(deserializer)?;
121+ let into_cursor = |mode: Mode| m.get(&mode).copied().unwrap_or_default();
122+ Ok(CursorShapeConfig([
123+ into_cursor(Mode::Normal),
124+ into_cursor(Mode::Select),
125+ into_cursor(Mode::Insert),
126+ ]))
127+ }
128+}
113129
114130impl std::ops::Deref for CursorShapeConfig {
115− type Target = HashMap<Mode, CursorKind>;
131+ type Target = [CursorKind; 3];
116132
117133 fn deref(&self) -> &Self::Target {
118134 &self.0
@@ -121,11 +137,7 @@ impl std::ops::Deref for CursorShapeConfig {
121137
122138impl Default for CursorShapeConfig {
123139 fn default() -> Self {
124− Self(hashmap!(
125− Mode::Insert => CursorKind::Block,
126− Mode::Normal => CursorKind::Block,
127− Mode::Select => CursorKind::Block,
128− ))
140+ Self([CursorKind::Block; 3])
129141 }
130142}
131143
@@ -621,7 +633,7 @@ impl Editor {
621633 let cursorkind = self
622634 .config
623635 .cursor_shape
624− .get(&doc.mode())
636+ .get(doc.mode() as usize)
625637 .copied()
626638 .unwrap_or_default();
627639 (Some(pos), cursorkind)