Browse Source

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

As reported by `cargo +nightly typesize`
issue-133
Manos Pitsidianakis 5 months ago
parent
commit
a7a50d3078
  1. 4
      src/components/mail/listing.rs
  2. 10
      src/components/mail/listing/compact.rs
  3. 6
      src/components/mail/listing/thread.rs
  4. 24
      src/state.rs
  5. 1
      src/terminal.rs

4
src/components/mail/listing.rs

@ -84,9 +84,9 @@ impl Default for Modifier {
#[derive(Debug, Default, Clone)]
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 segment_tree: [SegmentTree; 12],
pub segment_tree: Box<[SegmentTree; 12]>,
}
#[derive(Debug, Default)]

10
src/components/mail/listing/compact.rs

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

6
src/components/mail/listing/thread.rs

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

24
src/state.rs

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

1
src/terminal.rs

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

Loading…
Cancel
Save