diff --git a/docs/changelog.md b/docs/changelog.md index 072e4d3e7..cca25f54d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -14,6 +14,7 @@ brief notes about them may accumulate here. * Fixed: improved conformance with xterm for keys like CTRL-6 and CTRL-/. [#556](https://github.com/wez/wezterm/discussions/556) * Fixed: detection and handling of fonts such as terminus-bold.otb that contain only bitmap strikes. [#560](https://github.com/wez/wezterm/issues/560) * Fixed: the pixel size reported by the pty to the kernel wasn't adjusted for font metrics/dpi until the config was reloaded or window resized. [#563](https://github.com/wez/wezterm/issues/563) +* Fixed: greatly reduce memory consumption when system fallback fonts are loaded [#559](https://github.com/wez/wezterm/issues/559) ### 20210314-114017-04b7cedd diff --git a/wezterm-font/src/ftwrap.rs b/wezterm-font/src/ftwrap.rs index a0385cea5..3c07ad1d9 100644 --- a/wezterm-font/src/ftwrap.rs +++ b/wezterm-font/src/ftwrap.rs @@ -4,6 +4,7 @@ use crate::locator::FontDataHandle; use anyhow::{anyhow, Context}; use config::{configuration, FreeTypeLoadTarget}; pub use freetype::*; +use std::borrow::Cow; use std::ptr; #[inline] @@ -58,9 +59,11 @@ pub fn compute_load_flags_from_config() -> (i32, FT_Render_Mode) { (load_flags as i32, render) } +type CowVecU8 = Cow<'static, [u8]>; + pub struct Face { pub face: FT_Face, - _bytes: Vec, + _bytes: CowVecU8, size: Option, } @@ -313,7 +316,7 @@ impl Library { self.new_face(path.to_str().unwrap(), *index as _) } FontDataHandle::Memory { data, index, .. } => { - self.new_face_from_slice(&data, *index as _) + self.new_face_from_slice(data.clone(), *index as _) } } } @@ -342,7 +345,7 @@ impl Library { face_index ) })?, - _bytes: vec![], + _bytes: CowVecU8::Borrowed(b""), size: None, }); } @@ -356,6 +359,7 @@ impl Library { path.display(), data.len() ); + let data = CowVecU8::Owned(data); let res = unsafe { FT_New_Memory_Face( @@ -379,8 +383,7 @@ impl Library { }) } - pub fn new_face_from_slice(&self, data: &[u8], face_index: FT_Long) -> anyhow::Result { - let data = data.to_vec(); + pub fn new_face_from_slice(&self, data: CowVecU8, face_index: FT_Long) -> anyhow::Result { let mut face = ptr::null_mut(); let res = unsafe {