src/: Box<_> some large fields in biggest types

As reported by `cargo +nightly typesize`
issue-133
Manos Pitsidianakis 2022-09-18 00:09:49 +03:00
parent b138d9bc61
commit a7a50d3078
5 changed files with 23 additions and 22 deletions

View File

@ -84,9 +84,9 @@ impl Default for Modifier {
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct DataColumns { pub struct DataColumns {
pub columns: [CellBuffer; 12], pub columns: Box<[CellBuffer; 12]>,
pub widths: [usize; 12], // widths of columns calculated in first draw and after size changes pub widths: [usize; 12], // widths of columns calculated in first draw and after size changes
pub segment_tree: [SegmentTree; 12], pub segment_tree: Box<[SegmentTree; 12]>,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]

View File

@ -188,7 +188,7 @@ pub struct CompactListing {
force_draw: bool, force_draw: bool,
/// If `self.view` exists or not. /// If `self.view` exists or not.
focus: Focus, focus: Focus,
view: ThreadView, view: Box<ThreadView>,
row_updates: SmallVec<[ThreadHash; 8]>, row_updates: SmallVec<[ThreadHash; 8]>,
color_cache: ColorCache, color_cache: ColorCache,
@ -307,7 +307,7 @@ impl MailListingTrait for CompactListing {
} else if self.unfocused() { } else if self.unfocused() {
let thread = self.get_thread_under_cursor(self.cursor_pos.2); let thread = self.get_thread_under_cursor(self.cursor_pos.2);
self.view = ThreadView::new(self.new_cursor_pos, thread, None, context); self.view = Box::new(ThreadView::new(self.new_cursor_pos, thread, None, context));
} }
} }
@ -491,7 +491,7 @@ impl ListingTrait for CompactListing {
fn set_coordinates(&mut self, coordinates: (AccountHash, MailboxHash)) { fn set_coordinates(&mut self, coordinates: (AccountHash, MailboxHash)) {
self.new_cursor_pos = (coordinates.0, coordinates.1, 0); self.new_cursor_pos = (coordinates.0, coordinates.1, 0);
self.focus = Focus::None; self.focus = Focus::None;
self.view = ThreadView::default(); self.view = Box::new(ThreadView::default());
self.filtered_selection.clear(); self.filtered_selection.clear();
self.filtered_order.clear(); self.filtered_order.clear();
self.filter_term.clear(); self.filter_term.clear();
@ -897,7 +897,7 @@ impl CompactListing {
rows: vec![], rows: vec![],
dirty: true, dirty: true,
force_draw: true, force_draw: true,
view: ThreadView::default(), view: Box::new(ThreadView::default()),
color_cache: ColorCache::default(), color_cache: ColorCache::default(),
movement: None, movement: None,
modifier_active: false, modifier_active: false,
@ -1785,7 +1785,7 @@ impl Component for CompactListing {
|| shortcut!(k == shortcuts[Listing::DESCRIPTION]["focus_right"])) => || shortcut!(k == shortcuts[Listing::DESCRIPTION]["focus_right"])) =>
{ {
let thread = self.get_thread_under_cursor(self.cursor_pos.2); let thread = self.get_thread_under_cursor(self.cursor_pos.2);
self.view = ThreadView::new(self.cursor_pos, thread, None, context); self.view = Box::new(ThreadView::new(self.cursor_pos, thread, None, context));
self.set_focus(Focus::Entry, context); self.set_focus(Focus::Entry, context);
return true; return true;
} }

View File

@ -131,7 +131,7 @@ pub struct ThreadListing {
/// If `self.view` is focused or not. /// If `self.view` is focused or not.
focus: Focus, focus: Focus,
initialised: bool, initialised: bool,
view: Option<MailView>, view: Option<Box<MailView>>,
movement: Option<PageMovement>, movement: Option<PageMovement>,
id: ComponentId, id: ComponentId,
} }
@ -773,7 +773,7 @@ impl ListingTrait for ThreadListing {
if let Some(ref mut v) = self.view { if let Some(ref mut v) = self.view {
v.update(coordinates, context); v.update(coordinates, context);
} else { } else {
self.view = Some(MailView::new(coordinates, None, None, context)); self.view = Some(Box::new(MailView::new(coordinates, None, None, context)));
} }
if let Some(ref mut s) = self.view { if let Some(ref mut s) = self.view {
@ -1239,7 +1239,7 @@ impl Component for ThreadListing {
if let Some(ref mut v) = self.view { if let Some(ref mut v) = self.view {
v.update(coordinates, context); v.update(coordinates, context);
} else { } else {
self.view = Some(MailView::new(coordinates, None, None, context)); self.view = Some(Box::new(MailView::new(coordinates, None, None, context)));
} }
if let Some(v) = self.view.as_mut() { if let Some(v) = self.view.as_mut() {

View File

@ -97,7 +97,7 @@ impl InputHandler {
/// A context container for loaded settings, accounts, UI changes, etc. /// A context container for loaded settings, accounts, UI changes, etc.
pub struct Context { pub struct Context {
pub accounts: IndexMap<AccountHash, Account>, pub accounts: IndexMap<AccountHash, Account>,
pub settings: Settings, pub settings: Box<Settings>,
/// Areas of the screen that must be redrawn in the next render /// Areas of the screen that must be redrawn in the next render
pub dirty_areas: VecDeque<Area>, pub dirty_areas: VecDeque<Area>,
@ -168,13 +168,13 @@ impl Context {
/// A State object to manage and own components and components of the UI. `State` is responsible for /// A State object to manage and own components and components of the UI. `State` is responsible for
/// managing the terminal and interfacing with `melib` /// managing the terminal and interfacing with `melib`
pub struct State { pub struct State {
screen: Screen, screen: Box<Screen>,
draw_rate_limit: RateLimit, draw_rate_limit: RateLimit,
child: Option<ForkType>, child: Option<ForkType>,
pub mode: UIMode, pub mode: UIMode,
overlay: Vec<Box<dyn Component>>, overlay: Vec<Box<dyn Component>>,
components: Vec<Box<dyn Component>>, components: Vec<Box<dyn Component>>,
pub context: Context, pub context: Box<Context>,
timer: thread::JoinHandle<()>, timer: thread::JoinHandle<()>,
display_messages: SmallVec<[DisplayMessage; 8]>, display_messages: SmallVec<[DisplayMessage; 8]>,
@ -228,11 +228,11 @@ impl State {
let input_thread_pipe = nix::unistd::pipe() let input_thread_pipe = nix::unistd::pipe()
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?; .map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?;
let backends = Backends::new(); let backends = Backends::new();
let settings = if let Some(settings) = settings { let settings = Box::new(if let Some(settings) = settings {
settings settings
} else { } else {
Settings::new()? Settings::new()?
}; });
/* /*
let mut plugin_manager = PluginManager::new(); let mut plugin_manager = PluginManager::new();
for (_, p) in settings.plugins.clone() { for (_, p) in settings.plugins.clone() {
@ -307,7 +307,7 @@ impl State {
let working = Arc::new(()); let working = Arc::new(());
let control = Arc::downgrade(&working); let control = Arc::downgrade(&working);
let mut s = State { let mut s = State {
screen: Screen { screen: Box::new(Screen {
cols, cols,
rows, rows,
grid: CellBuffer::new(cols, rows, Cell::with_char(' ')), grid: CellBuffer::new(cols, rows, Cell::with_char(' ')),
@ -319,7 +319,7 @@ impl State {
} else { } else {
Screen::draw_horizontal_segment_no_color Screen::draw_horizontal_segment_no_color
}, },
}, }),
child: None, child: None,
mode: UIMode::Normal, mode: UIMode::Normal,
components: Vec::with_capacity(8), components: Vec::with_capacity(8),
@ -333,7 +333,7 @@ impl State {
display_messages_dirty: false, display_messages_dirty: false,
display_messages_initialised: false, display_messages_initialised: false,
display_messages_area: ((0, 0), (0, 0)), display_messages_area: ((0, 0), (0, 0)),
context: Context { context: Box::new(Context {
accounts, accounts,
settings, settings,
dirty_areas: VecDeque::with_capacity(5), dirty_areas: VecDeque::with_capacity(5),
@ -351,7 +351,7 @@ impl State {
}, },
sender, sender,
receiver, receiver,
}, }),
}; };
if s.context.settings.terminal.ascii_drawing { if s.context.settings.terminal.ascii_drawing {
s.screen.grid.set_ascii_drawing(true); s.screen.grid.set_ascii_drawing(true);
@ -395,7 +395,7 @@ impl State {
} }
let Context { let Context {
ref mut accounts, .. ref mut accounts, ..
} = &mut self.context; } = &mut *self.context;
if let Some(notification) = accounts[&account_hash].reload(event, mailbox_hash) { if let Some(notification) = accounts[&account_hash].reload(event, mailbox_hash) {
if let UIEvent::Notification(_, _, _) = notification { if let UIEvent::Notification(_, _, _) = notification {
@ -948,10 +948,10 @@ impl State {
if toml::Value::try_from(&new_settings) == toml::Value::try_from(&self.context.settings) { if toml::Value::try_from(&new_settings) == toml::Value::try_from(&self.context.settings) {
return Err("No changes detected.".into()); return Err("No changes detected.".into());
} }
Ok(new_settings) Ok(Box::new(new_settings))
}) { }) {
Ok(new_settings) => { Ok(new_settings) => {
let old_settings = Box::new(std::mem::replace(&mut self.context.settings, new_settings)); let old_settings = std::mem::replace(&mut self.context.settings, new_settings);
self.context.replies.push_back(UIEvent::ConfigReload { self.context.replies.push_back(UIEvent::ConfigReload {
old_settings old_settings
}); });

View File

@ -463,6 +463,7 @@ pub mod screen {
use termion::{clear, cursor}; use termion::{clear, cursor};
pub type StateStdout = pub type StateStdout =
termion::screen::AlternateScreen<termion::raw::RawTerminal<BufWriter<std::io::Stdout>>>; termion::screen::AlternateScreen<termion::raw::RawTerminal<BufWriter<std::io::Stdout>>>;
pub struct Screen { pub struct Screen {
pub cols: usize, pub cols: usize,
pub rows: usize, pub rows: usize,