diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-01-08 17:04:44 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-01-20 15:58:59 +0200 |
commit | a365a846b8e8bca8f053e8f7152604e0103a7181 (patch) | |
tree | 0f797bdf1915e0e149fda161000912c9c5a21e03 /ui/src/components | |
parent | b6403f486b0ceefff46781bccca056a38ecd0577 (diff) |
Replace StackVec with smallvec::SmallVec
SmallVec has a less buggy and better implementation.
Diffstat (limited to 'ui/src/components')
-rw-r--r-- | ui/src/components/mail/listing.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 32 | ||||
-rw-r--r-- | ui/src/components/mail/listing/conversations.rs | 18 | ||||
-rw-r--r-- | ui/src/components/mail/listing/plain.rs | 18 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 10 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 7 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 2 |
7 files changed, 49 insertions, 47 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 1157e03c..69a93e8b 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -21,6 +21,7 @@ use super::*; use crate::types::segment_tree::SegmentTree; +use smallvec::SmallVec; mod conversations; pub use self::conversations::*; @@ -56,10 +57,10 @@ pub trait MailListingTrait: ListingTrait { a: &ListingAction, ) { let account = &mut context.accounts[self.coordinates().0]; - let mut envs_to_set: StackVec<EnvelopeHash> = StackVec::new(); + let mut envs_to_set: SmallVec<[EnvelopeHash; 8]> = SmallVec::new(); let folder_hash = account[self.coordinates().1].unwrap().folder.hash(); { - let mut stack = StackVec::new(); + let mut stack: SmallVec<[ThreadHash; 8]> = SmallVec::new(); stack.push(thread_hash); while let Some(thread_iter) = stack.pop() { { @@ -138,8 +139,8 @@ pub trait MailListingTrait: ListingTrait { } } - fn row_updates(&mut self) -> &mut StackVec<ThreadHash>; - fn get_focused_items(&self, _context: &Context) -> StackVec<ThreadHash>; + fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]>; + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]>; } pub trait ListingTrait: Component { diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 0d4df95a..47f81d01 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -69,18 +69,18 @@ pub struct CompactListing { /// If `self.view` exists or not. unfocused: bool, view: ThreadView, - row_updates: StackVec<ThreadHash>, + row_updates: SmallVec<[ThreadHash; 8]>, movement: Option<PageMovement>, id: ComponentId, } impl MailListingTrait for CompactListing { - fn row_updates(&mut self) -> &mut StackVec<ThreadHash> { + fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]> { &mut self.row_updates } - fn get_focused_items(&self, context: &Context) -> StackVec<ThreadHash> { + fn get_focused_items(&self, context: &Context) -> SmallVec<[ThreadHash; 8]> { let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); let i = [self.get_thread_under_cursor(self.cursor_pos.2, context)]; let cursor_iter; @@ -96,7 +96,7 @@ impl MailListingTrait for CompactListing { .flatten() .chain(cursor_iter.into_iter().flatten()) .cloned(); - StackVec::from_iter(iter.into_iter()) + SmallVec::from_iter(iter.into_iter()) } } @@ -530,7 +530,7 @@ impl CompactListing { filtered_selection: Vec::new(), filtered_order: FnvHashMap::default(), selection: FnvHashMap::default(), - row_updates: StackVec::new(), + row_updates: SmallVec::new(), data_columns: DataColumns::default(), dirty: true, force_draw: true, @@ -554,7 +554,7 @@ impl CompactListing { .hash(); let folder = &context.accounts[self.cursor_pos.0].folder_confs[&folder_hash]; let mut tags = String::new(); - let mut colors = StackVec::new(); + let mut colors: SmallVec<[_; 8]> = SmallVec::new(); let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap(); if let Some(t) = backend_lck.tags() { let tags_lck = t.read().unwrap(); @@ -681,17 +681,17 @@ impl CompactListing { let mut rows = Vec::with_capacity(1024); let mut min_width = (0, 0, 0, 0, 0); let mut row_widths: ( - StackVec<u8>, - StackVec<u8>, - StackVec<u8>, - StackVec<u8>, - StackVec<u8>, + SmallVec<[u8; 1024]>, + SmallVec<[u8; 1024]>, + SmallVec<[u8; 1024]>, + SmallVec<[u8; 1024]>, + SmallVec<[u8; 1024]>, ) = ( - StackVec::new(), - StackVec::new(), - StackVec::new(), - StackVec::new(), - StackVec::new(), + SmallVec::new(), + SmallVec::new(), + SmallVec::new(), + SmallVec::new(), + SmallVec::new(), ); threads.sort_by(self.sort, self.subsort, &account.collection.envelopes); diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs index 3b72cdc4..3b322706 100644 --- a/ui/src/components/mail/listing/conversations.rs +++ b/ui/src/components/mail/listing/conversations.rs @@ -73,7 +73,7 @@ column_str!(struct DateString(String)); column_str!(struct FromString(String)); column_str!(struct SubjectString(String)); column_str!(struct FlagString(String)); -column_str!(struct TagString(String, StackVec<Color>)); +column_str!(struct TagString(String, SmallVec<[Color; 8]>)); /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a /// `ThreadView`. @@ -100,18 +100,18 @@ pub struct ConversationsListing { /// If `self.view` exists or not. unfocused: bool, view: ThreadView, - row_updates: StackVec<ThreadHash>, + row_updates: SmallVec<[ThreadHash; 8]>, movement: Option<PageMovement>, id: ComponentId, } impl MailListingTrait for ConversationsListing { - fn row_updates(&mut self) -> &mut StackVec<ThreadHash> { + fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]> { &mut self.row_updates } - fn get_focused_items(&self, context: &Context) -> StackVec<ThreadHash> { + fn get_focused_items(&self, context: &Context) -> SmallVec<[ThreadHash; 8]> { let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); let i = [self.get_thread_under_cursor(self.cursor_pos.2, context)]; let cursor_iter; @@ -127,7 +127,7 @@ impl MailListingTrait for ConversationsListing { .flatten() .chain(cursor_iter.into_iter().flatten()) .cloned(); - StackVec::from_iter(iter.into_iter()) + SmallVec::from_iter(iter.into_iter()) } } @@ -500,7 +500,7 @@ impl ConversationsListing { filtered_selection: Vec::new(), filtered_order: FnvHashMap::default(), selection: FnvHashMap::default(), - row_updates: StackVec::new(), + row_updates: SmallVec::new(), content: Default::default(), dirty: true, force_draw: true, @@ -525,7 +525,7 @@ impl ConversationsListing { .hash(); let folder = &context.accounts[self.cursor_pos.0].folder_confs[&folder_hash]; let mut tags = String::new(); - let mut colors = StackVec::new(); + let mut colors = SmallVec::new(); let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap(); if let Some(t) = backend_lck.tags() { let tags_lck = t.read().unwrap(); @@ -690,7 +690,7 @@ impl ConversationsListing { } from_address_list.clear(); from_address_set.clear(); - let mut stack = StackVec::new(); + let mut stack: SmallVec<[ThreadHash; 8]> = SmallVec::new(); stack.push(root_idx); while let Some(h) = stack.pop() { let env_hash = if let Some(h) = threads.thread_nodes()[&h].message() { @@ -952,7 +952,7 @@ impl ConversationsListing { let mut from_address_list = Vec::new(); let mut from_address_set: std::collections::HashSet<Vec<u8>> = std::collections::HashSet::new(); - let mut stack = StackVec::new(); + let mut stack: SmallVec<[ThreadHash; 8]> = SmallVec::new(); stack.push(thread_hash); while let Some(h) = stack.pop() { let env_hash = if let Some(h) = threads.thread_nodes()[&h].message() { diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index b1f8de8c..c2410416 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -70,19 +70,19 @@ pub struct PlainListing { /// If `self.view` exists or not. unfocused: bool, view: MailView, - row_updates: StackVec<EnvelopeHash>, - _row_updates: StackVec<ThreadHash>, + row_updates: SmallVec<[EnvelopeHash; 8]>, + _row_updates: SmallVec<[ThreadHash; 8]>, movement: Option<PageMovement>, id: ComponentId, } impl MailListingTrait for PlainListing { - fn row_updates(&mut self) -> &mut StackVec<ThreadHash> { + fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]> { &mut self._row_updates } - fn get_focused_items(&self, context: &Context) -> StackVec<ThreadHash> { + fn get_focused_items(&self, context: &Context) -> SmallVec<[ThreadHash; 8]> { let is_selection_empty = self.selection.values().cloned().any(std::convert::identity); if is_selection_empty { self.selection @@ -91,7 +91,7 @@ impl MailListingTrait for PlainListing { .map(|(k, _)| self.thread_hashes[k]) .collect() } else { - let mut ret = StackVec::new(); + let mut ret = SmallVec::new(); ret.push(self.get_thread_under_cursor(self.cursor_pos.2, context)); ret } @@ -484,8 +484,8 @@ impl PlainListing { filtered_selection: Vec::new(), filtered_order: FnvHashMap::default(), selection: FnvHashMap::default(), - row_updates: StackVec::new(), - _row_updates: StackVec::new(), + row_updates: SmallVec::new(), + _row_updates: SmallVec::new(), data_columns: DataColumns::default(), dirty: true, force_draw: true, @@ -503,7 +503,7 @@ impl PlainListing { .hash(); let folder = &context.accounts[self.cursor_pos.0].folder_confs[&folder_hash]; let mut tags = String::new(); - let mut colors = StackVec::new(); + let mut colors = SmallVec::new(); let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap(); if let Some(t) = backend_lck.tags() { let tags_lck = t.read().unwrap(); @@ -1086,7 +1086,7 @@ impl Component for PlainListing { .flatten() .chain(cursor_iter.into_iter().flatten()) .cloned(); - let stack = StackVec::from_iter(iter.into_iter()); + let stack: SmallVec<[_; 8]> = SmallVec::from_iter(iter.into_iter()); for i in stack { self.perform_action(context, i, a); } diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index eb25a2ec..6a81a735 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -37,7 +37,7 @@ pub struct ThreadListing { /// Cache current view. content: CellBuffer, - row_updates: StackVec<ThreadHash>, + row_updates: SmallVec<[ThreadHash; 8]>, locations: Vec<EnvelopeHash>, /// If we must redraw on next redraw event dirty: bool, @@ -50,12 +50,12 @@ pub struct ThreadListing { } impl MailListingTrait for ThreadListing { - fn row_updates(&mut self) -> &mut StackVec<ThreadHash> { + fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]> { &mut self.row_updates } - fn get_focused_items(&self, _context: &Context) -> StackVec<ThreadHash> { - StackVec::new() + fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> { + SmallVec::new() } } @@ -242,7 +242,7 @@ impl ThreadListing { sort: (Default::default(), Default::default()), subsort: (Default::default(), Default::default()), content, - row_updates: StackVec::new(), + row_updates: SmallVec::new(), locations: Vec::new(), dirty: true, unfocused: false, diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 7fcf78b4..630be357 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -22,6 +22,7 @@ use super::*; use melib::list_management; use melib::parser::BytesExt; +use smallvec::SmallVec; use std::convert::TryFrom; use std::process::{Command, Stdio}; @@ -229,7 +230,7 @@ impl MailView { if body.count_attachments() > 1 { fn attachment_tree( (idx, (depth, att)): (&mut usize, (usize, &Attachment)), - branches: &mut StackVec<bool>, + branches: &mut SmallVec<[bool; 8]>, has_sibling: bool, s: &mut String, ) { @@ -286,7 +287,7 @@ impl MailView { _ => {} } } - attachment_tree((&mut 0, (0, &body)), &mut StackVec::new(), false, &mut t); + attachment_tree((&mut 0, (0, &body)), &mut SmallVec::new(), false, &mut t); } t } @@ -1385,7 +1386,7 @@ impl Component for MailView { } _ => { /* error print message to user */ } } - } + }; } UIEvent::Action(Listing(OpenInNewTab)) => { context diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 9cdb3110..5964e356 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -848,7 +848,7 @@ impl ThreadView { .iter() .enumerate() .fold( - (vec![Vec::new()], StackVec::new(), false), + (vec![Vec::new()], SmallVec::<[_; 8]>::new(), false), |(mut visies, mut stack, is_prev_hidden), (idx, e)| { match (e.hidden, is_prev_hidden) { (true, false) => { |