Browse Source

Remove fnv crate

async
Manos Pitsidianakis 2 years ago
parent
commit
eb701695f7
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 2
      Cargo.lock
  2. 1
      Cargo.toml
  3. 1
      melib/Cargo.toml
  4. 20
      melib/src/addressbook.rs
  5. 8
      melib/src/addressbook/vcard.rs
  6. 12
      melib/src/backends.rs
  7. 29
      melib/src/backends/imap.rs
  8. 8
      melib/src/backends/imap/connection.rs
  9. 2
      melib/src/backends/imap/watch.rs
  10. 15
      melib/src/backends/jmap.rs
  11. 2
      melib/src/backends/jmap/connection.rs
  12. 3
      melib/src/backends/jmap/protocol.rs
  13. 40
      melib/src/backends/maildir/backend.rs
  14. 10
      melib/src/backends/mbox.rs
  15. 17
      melib/src/backends/notmuch.rs
  16. 30
      melib/src/collection.rs
  17. 8
      melib/src/email.rs
  18. 10
      melib/src/email/compose.rs
  19. 1
      melib/src/lib.rs
  20. 53
      melib/src/thread.rs
  21. 6
      melib/src/thread/iterators.rs
  22. 1
      src/bin.rs
  23. 6
      src/components.rs
  24. 4
      src/components/contacts.rs
  25. 3
      src/components/mail/listing.rs
  26. 16
      src/components/mail/listing/compact.rs
  27. 16
      src/components/mail/listing/conversations.rs
  28. 20
      src/components/mail/listing/plain.rs
  29. 6
      src/components/mail/listing/thread.rs
  30. 7
      src/components/utilities.rs
  31. 10
      src/components/utilities/widgets.rs
  32. 16
      src/conf/accounts.rs
  33. 4
      src/conf/shortcuts.rs
  34. 4
      src/mailcap.rs
  35. 1
      src/managesieve.rs
  36. 8
      src/plugins/backend.rs
  37. 6
      src/state.rs
  38. 14
      src/workers.rs

2
Cargo.lock

@ -685,7 +685,6 @@ dependencies = [
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"linkify 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"melib 0.5.0",
@ -720,7 +719,6 @@ dependencies = [
"crossbeam 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",

1
Cargo.toml

@ -34,7 +34,6 @@ serde = "1.0.71"
serde_derive = "1.0.71"
serde_json = "1.0"
toml = "0.5.3"
fnv = "1.0.3" # >:c
linkify = "0.3.1" # >:c
xdg-utils = "0.3.0"
nom = "3.2.0"

1
melib/Cargo.toml

@ -22,7 +22,6 @@ bitflags = "1.0"
crossbeam = "0.7.2"
data-encoding = "2.1.1"
encoding = "0.2.33"
fnv = "1.0.3"
memmap = { version = "0.5.2", optional = true }
nom = "3.2.0"
notify = { version = "4.0.1", optional = true }

20
melib/src/addressbook.rs

@ -23,7 +23,7 @@
pub mod vcard;
use crate::datetime::{self, UnixTimestamp};
use fnv::FnvHashMap;
use std::collections::HashMap;
use uuid::Uuid;
use std::ops::Deref;
@ -61,7 +61,7 @@ pub struct AddressBook {
display_name: String,
created: UnixTimestamp,
last_edited: UnixTimestamp,
pub cards: FnvHashMap<CardId, Card>,
pub cards: HashMap<CardId, Card>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
@ -80,7 +80,7 @@ pub struct Card {
color: u8,
last_edited: UnixTimestamp,
extra_properties: FnvHashMap<String, String>,
extra_properties: HashMap<String, String>,
/// If true, we can't make any changes because we do not manage this resource.
external_resource: bool,
@ -92,7 +92,7 @@ impl AddressBook {
display_name,
created: datetime::now(),
last_edited: datetime::now(),
cards: FnvHashMap::default(),
cards: HashMap::default(),
}
}
@ -132,9 +132,9 @@ impl AddressBook {
}
impl Deref for AddressBook {
type Target = FnvHashMap<CardId, Card>;
type Target = HashMap<CardId, Card>;
fn deref(&self) -> &FnvHashMap<CardId, Card> {
fn deref(&self) -> &HashMap<CardId, Card> {
&self.cards
}
}
@ -156,7 +156,7 @@ impl Card {
last_edited: datetime::now(),
external_resource: false,
extra_properties: FnvHashMap::default(),
extra_properties: HashMap::default(),
color: 0,
}
}
@ -229,7 +229,7 @@ impl Card {
self.extra_properties.get(key).map(String::as_str)
}
pub fn extra_properties(&self) -> &FnvHashMap<String, String> {
pub fn extra_properties(&self) -> &HashMap<String, String> {
&self.extra_properties
}
@ -242,8 +242,8 @@ impl Card {
}
}
impl From<FnvHashMap<String, String>> for Card {
fn from(mut map: FnvHashMap<String, String>) -> Card {
impl From<HashMap<String, String>> for Card {
fn from(mut map: HashMap<String, String>) -> Card {
let mut card = Card::new();
if let Some(val) = map.remove("TITLE") {
card.title = val;

8
melib/src/addressbook/vcard.rs

@ -23,7 +23,7 @@
use super::*;
use crate::error::{MeliError, Result};
use crate::parsec::{match_literal_anycase, one_or_more, peek, prefix, take_until, Parser};
use fnv::FnvHashMap;
use std::collections::HashMap;
use std::convert::TryInto;
/* Supported vcard versions */
@ -50,14 +50,14 @@ static FOOTER: &'static str = "END:VCARD\r\n";
#[derive(Debug)]
pub struct VCard<T: VCardVersion>(
fnv::FnvHashMap<String, ContentLine>,
HashMap<String, ContentLine>,
std::marker::PhantomData<*const T>,
);
impl<V: VCardVersion> VCard<V> {
pub fn new_v4() -> VCard<impl VCardVersion> {
VCard(
FnvHashMap::default(),
HashMap::default(),
std::marker::PhantomData::<*const VCardVersion4>,
)
}
@ -78,7 +78,7 @@ impl CardDeserializer {
&input[HEADER.len()..input.len() - FOOTER.len()]
};
let mut ret = FnvHashMap::default();
let mut ret = HashMap::default();
enum Stage {
Group,

12
melib/src/backends.rs

@ -64,8 +64,8 @@ use std::fmt::Debug;
use std::ops::Deref;
use std::sync::{Arc, RwLock};
use fnv::FnvHashMap;
use std;
use std::collections::HashMap;
#[macro_export]
macro_rules! get_path_hash {
@ -88,7 +88,7 @@ pub type BackendCreator = Box<
/// A hashmap containing all available mail backends.
/// An abstraction over any available backends.
pub struct Backends {
map: FnvHashMap<std::string::String, Backend>,
map: HashMap<std::string::String, Backend>,
}
pub struct Backend {
@ -111,7 +111,7 @@ pub const NOTMUCH_ERROR_MSG: &'static str = "this version of meli is not compile
impl Backends {
pub fn new() -> Self {
let mut b = Backends {
map: FnvHashMap::with_capacity_and_hasher(1, Default::default()),
map: HashMap::with_capacity_and_hasher(1, Default::default()),
};
#[cfg(feature = "maildir_backend")]
{
@ -284,7 +284,7 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
sender: RefreshEventConsumer,
work_context: WorkContext,
) -> Result<std::thread::ThreadId>;
fn mailboxes(&self) -> Result<FnvHashMap<MailboxHash, Mailbox>>;
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>>;
fn operation(&self, hash: EnvelopeHash) -> Box<dyn BackendOp>;
fn save(&self, bytes: &[u8], mailbox: &str, flags: Option<Flag>) -> Result<()>;
@ -303,14 +303,14 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
fn create_mailbox(
&mut self,
_path: String,
) -> Result<(MailboxHash, FnvHashMap<MailboxHash, Mailbox>)> {
) -> Result<(MailboxHash, HashMap<MailboxHash, Mailbox>)> {
Err(MeliError::new("Unimplemented."))
}
fn delete_mailbox(
&mut self,
_mailbox_hash: MailboxHash,
) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
) -> Result<HashMap<MailboxHash, Mailbox>> {
Err(MeliError::new("Unimplemented."))
}

29
melib/src/backends/imap.rs

@ -43,8 +43,8 @@ use crate::backends::{BackendMailbox, MailBackend, Mailbox, RefreshEventConsumer
use crate::conf::AccountSettings;
use crate::email::*;
use crate::error::{MeliError, Result};
use fnv::{FnvHashMap, FnvHashSet};
use std::collections::{hash_map::DefaultHasher, BTreeMap};
use std::collections::{HashMap, HashSet};
use std::hash::Hasher;
use std::str::FromStr;
use std::sync::{Arc, Mutex, RwLock};
@ -87,7 +87,7 @@ impl std::ops::Deref for IsSubscribedFn {
&self.0
}
}
type Capabilities = FnvHashSet<Vec<u8>>;
type Capabilities = HashSet<Vec<u8>>;
#[macro_export]
macro_rules! get_conf_val {
@ -120,11 +120,11 @@ macro_rules! get_conf_val {
#[derive(Debug)]
pub struct UIDStore {
uidvalidity: Arc<Mutex<FnvHashMap<MailboxHash, UID>>>,
hash_index: Arc<Mutex<FnvHashMap<EnvelopeHash, (UID, MailboxHash)>>>,
uid_index: Arc<Mutex<FnvHashMap<UID, EnvelopeHash>>>,
uidvalidity: Arc<Mutex<HashMap<MailboxHash, UID>>>,
hash_index: Arc<Mutex<HashMap<EnvelopeHash, (UID, MailboxHash)>>>,
uid_index: Arc<Mutex<HashMap<UID, EnvelopeHash>>>,
byte_cache: Arc<Mutex<FnvHashMap<UID, EnvelopeCache>>>,
byte_cache: Arc<Mutex<HashMap<UID, EnvelopeCache>>>,
}
#[derive(Debug)]
pub struct ImapType {
@ -137,7 +137,7 @@ pub struct ImapType {
can_create_flags: Arc<Mutex<bool>>,
tag_index: Arc<RwLock<BTreeMap<u64, String>>>,
mailboxes: Arc<RwLock<FnvHashMap<MailboxHash, ImapMailbox>>>,
mailboxes: Arc<RwLock<HashMap<MailboxHash, ImapMailbox>>>,
}
#[inline(always)]
@ -407,7 +407,7 @@ impl MailBackend for ImapType {
Ok(handle.thread().id())
}
fn mailboxes(&self) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>> {
{
let mailboxes = self.mailboxes.read().unwrap();
if !mailboxes.is_empty() {
@ -420,10 +420,7 @@ impl MailBackend for ImapType {
let mut mailboxes = self.mailboxes.write()?;
*mailboxes = ImapType::imap_mailboxes(&self.connection)?;
mailboxes.retain(|_, f| (self.is_subscribed)(f.path()));
let keys = mailboxes
.keys()
.cloned()
.collect::<FnvHashSet<MailboxHash>>();
let keys = mailboxes.keys().cloned().collect::<HashSet<MailboxHash>>();
let mut uid_lock = self.uid_store.uidvalidity.lock().unwrap();
for f in mailboxes.values_mut() {
uid_lock.entry(f.hash()).or_default();
@ -512,7 +509,7 @@ impl MailBackend for ImapType {
fn create_mailbox(
&mut self,
mut path: String,
) -> Result<(MailboxHash, FnvHashMap<MailboxHash, Mailbox>)> {
) -> Result<(MailboxHash, HashMap<MailboxHash, Mailbox>)> {
/* Must transform path to something the IMAP server will accept
*
* Each root mailbox has a hierarchy delimeter reported by the LIST entry. All paths
@ -566,7 +563,7 @@ impl MailBackend for ImapType {
fn delete_mailbox(
&mut self,
mailbox_hash: MailboxHash,
) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
) -> Result<HashMap<MailboxHash, Mailbox>> {
let mut mailboxes = self.mailboxes.write().unwrap();
let permissions = mailboxes[&mailbox_hash].permissions();
if !permissions.delete_mailbox {
@ -939,8 +936,8 @@ impl ImapType {
pub fn imap_mailboxes(
connection: &Arc<Mutex<ImapConnection>>,
) -> Result<FnvHashMap<MailboxHash, ImapMailbox>> {
let mut mailboxes: FnvHashMap<MailboxHash, ImapMailbox> = Default::default();
) -> Result<HashMap<MailboxHash, ImapMailbox>> {
let mut mailboxes: HashMap<MailboxHash, ImapMailbox> = Default::default();
let mut res = String::with_capacity(8 * 1024);
let mut conn = try_lock(&connection)?;
conn.send_command(b"LIST \"\" \"*\"")?;

8
melib/src/backends/imap/connection.rs

@ -25,8 +25,8 @@ use crate::error::*;
use std::io::Read;
use std::io::Write;
extern crate native_tls;
use fnv::FnvHashSet;
use native_tls::TlsConnector;
use std::collections::HashSet;
use std::iter::FromIterator;
use std::net::SocketAddr;
use std::sync::{Arc, Mutex};
@ -241,9 +241,7 @@ impl ImapStream {
capabilities = protocol_parser::capabilities(l.as_bytes())
.to_full_result()
.map(|capabilities| {
FnvHashSet::from_iter(
capabilities.into_iter().map(|s: &[u8]| s.to_vec()),
)
HashSet::from_iter(capabilities.into_iter().map(|s: &[u8]| s.to_vec()))
})
.ok();
}
@ -270,7 +268,7 @@ impl ImapStream {
ret.send_command(b"CAPABILITY")?;
ret.read_response(&mut res).unwrap();
let capabilities = protocol_parser::capabilities(res.as_bytes()).to_full_result()?;
let capabilities = FnvHashSet::from_iter(capabilities.into_iter().map(|s| s.to_vec()));
let capabilities = HashSet::from_iter(capabilities.into_iter().map(|s| s.to_vec()));
Ok((capabilities, ret))
} else {
let capabilities = capabilities.unwrap();

2
melib/src/backends/imap/watch.rs

@ -28,7 +28,7 @@ pub struct ImapWatchKit {
pub is_online: Arc<Mutex<(Instant, Result<()>)>>,
pub main_conn: Arc<Mutex<ImapConnection>>,
pub uid_store: Arc<UIDStore>,
pub mailboxes: Arc<RwLock<FnvHashMap<MailboxHash, ImapMailbox>>>,
pub mailboxes: Arc<RwLock<HashMap<MailboxHash, ImapMailbox>>>,
pub sender: RefreshEventConsumer,
pub work_context: WorkContext,
pub tag_index: Arc<RwLock<BTreeMap<u64, String>>>,

15
melib/src/backends/jmap.rs

@ -26,9 +26,8 @@ use crate::backends::{BackendMailbox, MailBackend, Mailbox, RefreshEventConsumer
use crate::conf::AccountSettings;
use crate::email::*;
use crate::error::{MeliError, Result};
use fnv::FnvHashMap;
use reqwest::blocking::Client;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashMap};
use std::str::FromStr;
use std::sync::{Arc, Mutex, RwLock};
use std::time::Instant;
@ -175,9 +174,9 @@ macro_rules! get_conf_val {
#[derive(Debug, Default)]
pub struct Store {
byte_cache: FnvHashMap<EnvelopeHash, EnvelopeCache>,
id_store: FnvHashMap<EnvelopeHash, Id>,
blob_id_store: FnvHashMap<EnvelopeHash, Id>,
byte_cache: HashMap<EnvelopeHash, EnvelopeCache>,
id_store: HashMap<EnvelopeHash, Id>,
blob_id_store: HashMap<EnvelopeHash, Id>,
}
#[derive(Debug)]
@ -189,7 +188,7 @@ pub struct JmapType {
connection: Arc<JmapConnection>,
store: Arc<RwLock<Store>>,
tag_index: Arc<RwLock<BTreeMap<u64, String>>>,
mailboxes: Arc<RwLock<FnvHashMap<MailboxHash, JmapMailbox>>>,
mailboxes: Arc<RwLock<HashMap<MailboxHash, JmapMailbox>>>,
}
impl MailBackend for JmapType {
@ -239,7 +238,7 @@ impl MailBackend for JmapType {
Err(MeliError::from("JMAP watch for updates is unimplemented"))
}
fn mailboxes(&self) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>> {
if self.mailboxes.read().unwrap().is_empty() {
let mailboxes = std::dbg!(protocol::get_mailboxes(&self.connection))?;
*self.mailboxes.write().unwrap() = mailboxes;
@ -291,7 +290,7 @@ impl JmapType {
connection: Arc::new(JmapConnection::new(&server_conf, online.clone())?),
store: Arc::new(RwLock::new(Store::default())),
tag_index: Arc::new(RwLock::new(Default::default())),
mailboxes: Arc::new(RwLock::new(FnvHashMap::default())),
mailboxes: Arc::new(RwLock::new(HashMap::default())),
account_name: s.name.clone(),
online,
is_subscribed: Arc::new(IsSubscribedFn(is_subscribed)),

2
melib/src/backends/jmap/connection.rs

@ -29,7 +29,7 @@ pub struct JmapConnection {
pub online_status: Arc<Mutex<(Instant, Result<()>)>>,
pub server_conf: JmapServerConf,
pub account_id: Arc<Mutex<String>>,
pub method_call_states: Arc<Mutex<FnvHashMap<&'static str, String>>>,
pub method_call_states: Arc<Mutex<HashMap<&'static str, String>>>,
}
impl JmapConnection {

3
melib/src/backends/jmap/protocol.rs

@ -25,6 +25,7 @@ use serde::Serialize;
use serde_json::{json, Value};
use smallvec::SmallVec;
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::hash::{Hash, Hasher};
@ -94,7 +95,7 @@ impl Request {
}
}
pub fn get_mailboxes(conn: &JmapConnection) -> Result<FnvHashMap<MailboxHash, JmapMailbox>> {
pub fn get_mailboxes(conn: &JmapConnection) -> Result<HashMap<MailboxHash, JmapMailbox>> {
let seq = get_request_no!(conn.request_no);
let res = conn
.client

40
melib/src/backends/maildir/backend.rs

@ -34,10 +34,10 @@ extern crate notify;
use self::notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use std::time::Duration;
use fnv::{FnvHashMap, FnvHashSet, FnvHasher};
use std::collections::{HashMap, HashSet, hash_map::DefaultHasher};
use std::ffi::OsStr;
use std::fs;
use std::hash::{Hash, Hasher};
use std::hash::{Hasher, Hash};
use std::io::{self, Read, Write};
use std::ops::{Deref, DerefMut};
use std::os::unix::fs::PermissionsExt;
@ -87,31 +87,31 @@ impl From<PathBuf> for MaildirPath {
#[derive(Debug, Default)]
pub struct HashIndex {
index: FnvHashMap<EnvelopeHash, MaildirPath>,
index: HashMap<EnvelopeHash, MaildirPath>,
hash: MailboxHash,
}
impl Deref for HashIndex {
type Target = FnvHashMap<EnvelopeHash, MaildirPath>;
fn deref(&self) -> &FnvHashMap<EnvelopeHash, MaildirPath> {
type Target = HashMap<EnvelopeHash, MaildirPath>;
fn deref(&self) -> &HashMap<EnvelopeHash, MaildirPath> {
&self.index
}
}
impl DerefMut for HashIndex {
fn deref_mut(&mut self) -> &mut FnvHashMap<EnvelopeHash, MaildirPath> {
fn deref_mut(&mut self) -> &mut HashMap<EnvelopeHash, MaildirPath> {
&mut self.index
}
}
pub type HashIndexes = Arc<Mutex<FnvHashMap<MailboxHash, HashIndex>>>;
pub type HashIndexes = Arc<Mutex<HashMap<MailboxHash, HashIndex>>>;
/// Maildir backend https://cr.yp.to/proto/maildir.html
#[derive(Debug)]
pub struct MaildirType {
name: String,
mailboxes: FnvHashMap<MailboxHash, MaildirMailbox>,
mailbox_index: Arc<Mutex<FnvHashMap<EnvelopeHash, MailboxHash>>>,
mailboxes: HashMap<MailboxHash, MaildirMailbox>,
mailbox_index: Arc<Mutex<HashMap<EnvelopeHash, MailboxHash>>>,
hash_indexes: HashIndexes,
path: PathBuf,
}
@ -150,11 +150,11 @@ pub(super) fn get_file_hash(file: &Path) -> EnvelopeHash {
let mut f = fs::File::open(&file).unwrap_or_else(|_| panic!("Can't open {}", file.display()));
f.read_to_end(&mut buf)
.unwrap_or_else(|_| panic!("Can't read {}", file.display()));
let mut hasher = FnvHasher::default();
let mut hasher = DefaultHasher::default();
hasher.write(&buf);
hasher.finish()
*/
let mut hasher = FnvHasher::default();
let mut hasher = DefaultHasher::default();
file.hash(&mut hasher);
hasher.finish()
}
@ -181,7 +181,7 @@ impl MailBackend for MaildirType {
Ok(())
}
fn mailboxes(&self) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>> {
Ok(self
.mailboxes
.iter()
@ -238,7 +238,7 @@ impl MailBackend for MaildirType {
let mut current_hashes = {
let mut map = map.lock().unwrap();
let map = map.entry(mailbox_hash).or_default();
map.keys().cloned().collect::<FnvHashSet<EnvelopeHash>>()
map.keys().cloned().collect::<HashSet<EnvelopeHash>>()
};
for file in files {
let hash = get_file_hash(&file);
@ -324,7 +324,7 @@ impl MailBackend for MaildirType {
.mailboxes
.iter()
.map(|(&k, v)| (k, (v.unseen.clone(), v.total.clone())))
.collect::<FnvHashMap<MailboxHash, (Arc<Mutex<usize>>, Arc<Mutex<usize>>)>>();
.collect::<HashMap<MailboxHash, (Arc<Mutex<usize>>, Arc<Mutex<usize>>)>>();
let handle = thread::Builder::new()
.name("mailbox watch".to_string())
.spawn(move || {
@ -655,7 +655,7 @@ impl MailBackend for MaildirType {
fn create_mailbox(
&mut self,
new_path: String,
) -> Result<(MailboxHash, FnvHashMap<MailboxHash, Mailbox>)> {
) -> Result<(MailboxHash, HashMap<MailboxHash, Mailbox>)> {
let mut path = self.path.clone();
path.push(&new_path);
if !path.starts_with(&self.path) {
@ -700,7 +700,7 @@ impl MailBackend for MaildirType {
fn delete_mailbox(
&mut self,
_mailbox_hash: MailboxHash,
) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
) -> Result<HashMap<MailboxHash, Mailbox>> {
Err(MeliError::new("Unimplemented."))
}
@ -726,9 +726,9 @@ impl MaildirType {
settings: &AccountSettings,
is_subscribed: Box<dyn Fn(&str) -> bool>,
) -> Result<Box<dyn MailBackend>> {
let mut mailboxes: FnvHashMap<MailboxHash, MaildirMailbox> = Default::default();
let mut mailboxes: HashMap<MailboxHash, MaildirMailbox> = Default::default();
fn recurse_mailboxes<P: AsRef<Path>>(
mailboxes: &mut FnvHashMap<MailboxHash, MaildirMailbox>,
mailboxes: &mut HashMap<MailboxHash, MaildirMailbox>,
settings: &AccountSettings,
p: P,
) -> Result<Vec<MailboxHash>> {
@ -820,12 +820,12 @@ impl MaildirType {
}
let mut hash_indexes =
FnvHashMap::with_capacity_and_hasher(mailboxes.len(), Default::default());
HashMap::with_capacity_and_hasher(mailboxes.len(), Default::default());
for &fh in mailboxes.keys() {
hash_indexes.insert(
fh,
HashIndex {
index: FnvHashMap::with_capacity_and_hasher(0, Default::default()),
index: HashMap::with_capacity_and_hasher(0, Default::default()),
hash: fh,
},
);

10
melib/src/backends/mbox.rs

@ -36,12 +36,12 @@ use crate::email::*;
use crate::error::{MeliError, Result};
use crate::get_path_hash;
use crate::shellexpand::ShellExpandTrait;
use fnv::FnvHashMap;
use libc;
use memmap::{Mmap, Protection};
use nom::{IResult, Needed};
extern crate notify;
use self::notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use std::collections::HashMap;
use std::fs::File;
use std::io::BufReader;
use std::io::Read;
@ -269,7 +269,7 @@ impl BackendOp for MboxOp {
}
pub fn mbox_parse(
index: Arc<Mutex<FnvHashMap<EnvelopeHash, (Offset, Length)>>>,
index: Arc<Mutex<HashMap<EnvelopeHash, (Offset, Length)>>>,
input: &[u8],
file_offset: usize,
) -> IResult<&[u8], Vec<Envelope>> {
@ -387,8 +387,8 @@ pub fn mbox_parse(
#[derive(Debug, Default)]
pub struct MboxType {
path: PathBuf,
index: Arc<Mutex<FnvHashMap<EnvelopeHash, (Offset, Length)>>>,
mailboxes: Arc<Mutex<FnvHashMap<MailboxHash, MboxMailbox>>>,
index: Arc<Mutex<HashMap<EnvelopeHash, (Offset, Length)>>>,
mailboxes: Arc<Mutex<HashMap<MailboxHash, MboxMailbox>>>,
}
impl MailBackend for MboxType {
@ -588,7 +588,7 @@ impl MailBackend for MboxType {
})?;
Ok(handle.thread().id())
}
fn mailboxes(&self) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>> {
Ok(self
.mailboxes
.lock()

17
melib/src/backends/notmuch.rs

@ -29,10 +29,11 @@ use crate::conf::AccountSettings;
use crate::email::{Envelope, EnvelopeHash, Flag};
use crate::error::{MeliError, Result};
use crate::shellexpand::ShellExpandTrait;
use fnv::FnvHashMap;
use smallvec::SmallVec;
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
use std::collections::{
hash_map::{DefaultHasher, HashMap},
BTreeMap,
};
use std::error::Error;
use std::ffi::{CStr, CString, OsStr};
use std::hash::{Hash, Hasher};
@ -104,8 +105,8 @@ impl Drop for DbConnection {
pub struct NotmuchDb {
lib: Arc<libloading::Library>,
revision_uuid: Arc<RwLock<u64>>,
mailboxes: Arc<RwLock<FnvHashMap<MailboxHash, NotmuchMailbox>>>,
index: Arc<RwLock<FnvHashMap<EnvelopeHash, CString>>>,
mailboxes: Arc<RwLock<HashMap<MailboxHash, NotmuchMailbox>>>,
index: Arc<RwLock<HashMap<EnvelopeHash, CString>>>,
tag_index: Arc<RwLock<BTreeMap<u64, String>>>,
path: PathBuf,
save_messages_to: Option<PathBuf>,
@ -199,7 +200,7 @@ impl NotmuchDb {
)));
}
let mut mailboxes = FnvHashMap::default();
let mut mailboxes = HashMap::default();
for (k, f) in s.mailboxes.iter() {
if let Some(query_str) = f.extra.get("query") {
let hash = {
@ -490,7 +491,7 @@ impl MailBackend for NotmuchDb {
})?;
Ok(handle.thread().id())
}
fn mailboxes(&self) -> Result<FnvHashMap<MailboxHash, Mailbox>> {
fn mailboxes(&self) -> Result<HashMap<MailboxHash, Mailbox>> {
Ok(self
.mailboxes
.read()
@ -533,7 +534,7 @@ impl MailBackend for NotmuchDb {
#[derive(Debug)]
struct NotmuchOp {
hash: EnvelopeHash,
index: Arc<RwLock<FnvHashMap<EnvelopeHash, CString>>>,
index: Arc<RwLock<HashMap<EnvelopeHash, CString>>>,
tag_index: Arc<RwLock<BTreeMap<u64, String>>>,
database: Arc<DbConnection>,
bytes: Option<String>,

30
melib/src/collection.rs

@ -27,10 +27,10 @@ use std::collections::BTreeMap;
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard};
use fnv::{FnvHashMap, FnvHashSet};
use std::collections::{HashMap, HashSet};
pub struct EnvelopeRef<'g> {
guard: RwLockReadGuard<'g, FnvHashMap<EnvelopeHash, Envelope>>,
guard: RwLockReadGuard<'g, HashMap<EnvelopeHash, Envelope>>,
env_hash: EnvelopeHash,
}
@ -43,7 +43,7 @@ impl Deref for EnvelopeRef<'_> {
}
pub struct EnvelopeRefMut<'g> {
guard: RwLockWriteGuard<'g, FnvHashMap<EnvelopeHash, Envelope>>,
guard: RwLockWriteGuard<'g, HashMap<EnvelopeHash, Envelope>>,
env_hash: EnvelopeHash,
}
@ -63,13 +63,13 @@ impl DerefMut for EnvelopeRefMut<'_> {
#[derive(Debug, Clone, Deserialize, Default, Serialize)]
pub struct Collection {
pub envelopes: Arc<RwLock<FnvHashMap<EnvelopeHash, Envelope>>>,
message_ids: FnvHashMap<Vec<u8>, EnvelopeHash>,
pub envelopes: Arc<RwLock<HashMap<EnvelopeHash, Envelope>>>,
message_ids: HashMap<Vec<u8>, EnvelopeHash>,
date_index: BTreeMap<UnixTimestamp, EnvelopeHash>,
subject_index: Option<BTreeMap<String, EnvelopeHash>>,
pub threads: FnvHashMap<MailboxHash, Threads>,
pub threads: HashMap<MailboxHash, Threads>,
sent_mailbox: Option<MailboxHash>,
pub mailboxes: FnvHashMap<MailboxHash, FnvHashSet<EnvelopeHash>>,
pub mailboxes: HashMap<MailboxHash, HashSet<EnvelopeHash>>,
}
impl Drop for Collection {
@ -93,17 +93,17 @@ impl Drop for Collection {
}
impl Collection {
pub fn new(envelopes: FnvHashMap<EnvelopeHash, Envelope>) -> Collection {
pub fn new(envelopes: HashMap<EnvelopeHash, Envelope>) -> Collection {
let date_index = BTreeMap::new();
let subject_index = None;
let message_ids = FnvHashMap::with_capacity_and_hasher(2048, Default::default());
let message_ids = HashMap::with_capacity_and_hasher(2048, Default::default());
/* Scrap caching for now. When a cached threads file is loaded, we must remove/rehash the
* thread nodes that shouldn't exist anymore (e.g. because their file moved from /new to
* /cur, or it was deleted).
*/
let threads = FnvHashMap::with_capacity_and_hasher(16, Default::default());
let mailboxes = FnvHashMap::with_capacity_and_hasher(16, Default::default());
let threads = HashMap::with_capacity_and_hasher(16, Default::default());
let mailboxes = HashMap::with_capacity_and_hasher(16, Default::default());
Collection {
envelopes: Arc::new(RwLock::new(envelopes)),
@ -190,7 +190,7 @@ impl Collection {
/// Returns a list of already existing mailboxs whose threads were updated
pub fn merge(
&mut self,
mut new_envelopes: FnvHashMap<EnvelopeHash, Envelope>,
mut new_envelopes: HashMap<EnvelopeHash, Envelope>,
mailbox_hash: MailboxHash,
sent_mailbox: Option<MailboxHash>,
) -> Option<SmallVec<[MailboxHash; 8]>> {
@ -407,14 +407,14 @@ impl Collection {
}
impl Index<&MailboxHash> for Collection {
type Output = FnvHashSet<EnvelopeHash>;
fn index(&self, index: &MailboxHash) -> &FnvHashSet<EnvelopeHash> {
type Output = HashSet<EnvelopeHash>;
fn index(&self, index: &MailboxHash) -> &HashSet<EnvelopeHash> {
&self.mailboxes[index]
}
}
impl IndexMut<&MailboxHash> for Collection {
fn index_mut(&mut self, index: &MailboxHash) -> &mut FnvHashSet<EnvelopeHash> {
fn index_mut(&mut self, index: &MailboxHash) -> &mut HashSet<EnvelopeHash> {
self.mailboxes.get_mut(index).unwrap()
}
}

8
melib/src/email.rs

@ -22,7 +22,7 @@
/*!
* Email parsing, handling, sending etc.
*/
use fnv::FnvHashMap;
use std::collections::HashMap;
mod compose;
pub use self::compose::*;
@ -138,7 +138,7 @@ pub struct Envelope {
message_id: MessageID,
in_reply_to: Option<MessageID>,
pub references: Option<References>,
other_headers: FnvHashMap<String, String>,
other_headers: HashMap<String, String>,
timestamp: UnixTimestamp,
thread: ThreadNodeHash,
@ -577,11 +577,11 @@ impl Envelope {
}
}
pub fn other_headers(&self) -> &FnvHashMap<String, String> {
pub fn other_headers(&self) -> &HashMap<String, String> {
&self.other_headers
}
pub fn other_headers_mut(&mut self) -> &mut FnvHashMap<String, String> {
pub fn other_headers_mut(&mut self) -> &mut HashMap<String, String> {
&mut self.other_headers
}

10
melib/src/email/compose.rs

@ -24,6 +24,7 @@ use crate::backends::BackendOp;
use crate::email::attachments::AttachmentBuilder;
use crate::shellexpand::ShellExpandTrait;
use data_encoding::BASE64_MIME;
use std::collections::HashMap;
use std::ffi::OsStr;
use std::io::Read;
use std::path::{Path, PathBuf};
@ -35,11 +36,10 @@ pub mod random;
//use self::mime::*;
use super::parser;
use fnv::FnvHashMap;
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Draft {
pub headers: FnvHashMap<String, String>,
pub headers: HashMap<String, String>,
pub header_order: Vec<String>,
pub body: String,
@ -48,7 +48,7 @@ pub struct Draft {
impl Default for Draft {
fn default() -> Self {
let mut headers = FnvHashMap::with_capacity_and_hasher(8, Default::default());
let mut headers = HashMap::with_capacity_and_hasher(8, Default::default());
let mut header_order = Vec::with_capacity(8);
headers.insert("From".into(), "".into());
headers.insert("To".into(), "".into());
@ -214,11 +214,11 @@ impl Draft {
ret
}
pub fn headers_mut(&mut self) -> &mut FnvHashMap<String, String> {
pub fn headers_mut(&mut self) -> &mut HashMap<String, String> {
&mut self.headers
}
pub fn headers(&self) -> &FnvHashMap<String, String> {
pub fn headers(&self) -> &HashMap<String, String> {
&self.headers
}

1
melib/src/lib.rs

@ -135,7 +135,6 @@ extern crate encoding;
#[macro_use]
extern crate bitflags;
extern crate fnv;
extern crate uuid;
pub use smallvec;

53
melib/src/thread.rs

@ -43,9 +43,9 @@ pub use iterators::*;
use crate::text_processing::grapheme_clusters::*;
use uuid::Uuid;
use fnv::{FnvHashMap, FnvHashSet};
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::iter::FromIterator;
use std::ops::Index;
@ -56,7 +56,7 @@ use std::sync::{Arc, RwLock};
use smallvec::SmallVec;
type Envelopes = Arc<RwLock<FnvHashMap<EnvelopeHash, Envelope>>>;
type Envelopes = Arc<RwLock<HashMap<EnvelopeHash, Envelope>>>;
macro_rules! uuid_hash_type {
($n:ident) => {
@ -407,15 +407,15 @@ impl ThreadNode {
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Threads {
pub thread_nodes: FnvHashMap<ThreadNodeHash, ThreadNode>,
pub thread_nodes: HashMap<ThreadNodeHash, ThreadNode>,
root_set: RefCell<Vec<ThreadNodeHash>>,
tree_index: RefCell<Vec<ThreadNodeHash>>,
pub groups: FnvHashMap<ThreadHash, ThreadGroup>,
pub groups: HashMap<ThreadHash, ThreadGroup>,
message_ids: FnvHashMap<Vec<u8>, ThreadNodeHash>,
pub message_ids_set: FnvHashSet<Vec<u8>>,
pub missing_message_ids: FnvHashSet<Vec<u8>>,
pub hash_set: FnvHashSet<EnvelopeHash>,
message_ids: HashMap<Vec<u8>, ThreadNodeHash>,
pub message_ids_set: HashSet<Vec<u8>>,
pub missing_message_ids: HashSet<Vec<u8>>,
pub hash_set: HashSet<EnvelopeHash>,
sort: RefCell<(SortField, SortOrder)>,
subsort: RefCell<(SortField, SortOrder)>,
}
@ -468,22 +468,19 @@ impl Threads {
/* To reconstruct thread information from the mails we need: */
/* a vector to hold thread members */
let thread_nodes: FnvHashMap<ThreadNodeHash, ThreadNode> =
FnvHashMap::with_capacity_and_hasher(
(length as f64 * 1.2) as usize,
Default::default(),
);
let thread_nodes: HashMap<ThreadNodeHash, ThreadNode> =
HashMap::with_capacity_and_hasher((length as f64 * 1.2) as usize, Default::default());
/* A hash table of Message IDs */
let message_ids: FnvHashMap<Vec<u8>, ThreadNodeHash> =
FnvHashMap::with_capacity_and_hasher(length, Default::default());
let message_ids: HashMap<Vec<u8>, ThreadNodeHash> =
HashMap::with_capacity_and_hasher(length, Default::default());
/* A hash set of Message IDs we haven't encountered yet as an Envelope */
let missing_message_ids: FnvHashSet<Vec<u8>> =
FnvHashSet::with_capacity_and_hasher(length, Default::default());
let missing_message_ids: HashSet<Vec<u8>> =
HashSet::with_capacity_and_hasher(length, Default::default());
/* A hash set of Message IDs we have encountered as a MessageID */
let message_ids_set: FnvHashSet<Vec<u8>> =
FnvHashSet::with_capacity_and_hasher(length, Default::default());
let hash_set: FnvHashSet<EnvelopeHash> =
FnvHashSet::with_capacity_and_hasher(length, Default::default());
let message_ids_set: HashSet<Vec<u8>> =
HashSet::with_capacity_and_hasher(length, Default::default());
let hash_set: HashSet<EnvelopeHash> =
HashSet::with_capacity_and_hasher(length, Default::default());
Threads {
thread_nodes,
@ -582,7 +579,7 @@ impl Threads {
pub fn amend(&mut self, envelopes: &mut Envelopes) {
let envelopes_lck = envelopes.read().unwrap();
let new_hash_set = FnvHashSet::from_iter(envelopes_lck.keys().cloned());
let new_hash_set = HashSet::from_iter(envelopes_lck.keys().cloned());
let difference: Vec<EnvelopeHash> =
self.hash_set.difference(&new_hash_set).cloned().collect();
@ -831,7 +828,7 @@ impl Threads {
.message_ids
.iter()
.map(|(a, &b)| (b, a.to_vec()))
.collect::<FnvHashMap<ThreadNodeHash, Vec<u8>>>(),
.collect::<HashMap<ThreadNodeHash, Vec<u8>>>(),
&envelopes,
);
*/
@ -1168,7 +1165,7 @@ impl Threads {
thread.message().unwrap()
}
pub fn thread_nodes(&self) -> &FnvHashMap<ThreadNodeHash, ThreadNode> {
pub fn thread_nodes(&self) -> &HashMap<ThreadNodeHash, ThreadNode> {
&self.thread_nodes
}
@ -1206,13 +1203,13 @@ impl Index<&ThreadNodeHash> for Threads {
/*
fn print_threadnodes(
node_hash: ThreadNodeHash,
nodes: &FnvHashMap<ThreadNodeHash, ThreadNode>,
nodes: &HashMap<ThreadNodeHash, ThreadNode>,
envelopes: &Envelopes,
) {
fn help(
level: usize,
node_hash: ThreadNodeHash,
nodes: &FnvHashMap<ThreadNodeHash, ThreadNode>,
nodes: &HashMap<ThreadNodeHash, ThreadNode>,
envelopes: &Envelopes,
) {
eprint!("{}ThreadNode {}\n{}\tmessage: {}\n{}\tparent: {}\n{}\tthread_group: {}\n{}\tchildren (len: {}):\n",
@ -1261,8 +1258,8 @@ struct Graph {
/*
fn save_graph(
node_arr: &[ThreadNodeHash],
nodes: &FnvHashMap<ThreadNodeHash, ThreadNode>,
ids: &FnvHashMap<ThreadNodeHash, Vec<u8>>,
nodes: &HashMap<ThreadNodeHash, ThreadNode>,
ids: &HashMap<ThreadNodeHash, Vec<u8>>,
envelopes: &Envelopes,
) {
let envelopes = envelopes.read().unwrap();

6
melib/src/thread/iterators.rs

@ -20,8 +20,8 @@
*/
use super::{ThreadNode, ThreadNodeHash};
use fnv::FnvHashMap;
use smallvec::SmallVec;
use std::collections::HashMap;
/* `ThreadsIterator` returns messages according to the sorted order. For example, for the following
* threads:
@ -42,7 +42,7 @@ pub struct ThreadsGroupIterator<'a> {
pub(super) root_tree: SmallVec<[ThreadNodeHash; 1024]>,
pub(super) pos: usize,
pub(super) stack: SmallVec<[usize; 16]>,
pub(super) thread_nodes: &'a FnvHashMap<ThreadNodeHash, ThreadNode>,
pub(super) thread_nodes: &'a HashMap<ThreadNodeHash, ThreadNode>,
}
impl<'a> Iterator for ThreadsGroupIterator<'a> {
type Item = (usize, ThreadNodeHash, bool);
@ -100,7 +100,7 @@ pub struct ThreadGroupIterator<'a> {
pub(super) group: ThreadNodeHash,
pub(super) pos: usize,
pub(super) stack: SmallVec<[usize; 16]>,
pub(super) thread_nodes: &'a FnvHashMap<ThreadNodeHash, ThreadNode>,
pub(super) thread_nodes: &'a HashMap<ThreadNodeHash, ThreadNode>,
}
impl<'a> Iterator for ThreadGroupIterator<'a> {

1
src/bin.rs

@ -37,7 +37,6 @@ extern crate serde_derive;
extern crate linkify;
extern crate uuid;
extern crate fnv;
extern crate termion;
#[macro_use]

6
src/components.rs

@ -43,15 +43,15 @@ pub use crate::contacts::*;
use std::fmt;
use std::fmt::{Debug, Display};
use fnv::FnvHashMap;
use std::collections::HashMap;
use uuid::Uuid;
use super::{Key, StatusEvent, UIEvent};
pub type ComponentId = Uuid;
pub type ShortcutMap = FnvHashMap<&'static str, Key>;
pub type ShortcutMaps = FnvHashMap<&'static str, ShortcutMap>;
pub type ShortcutMap = HashMap<&'static str, Key>;
pub type ShortcutMaps = HashMap<&'static str, ShortcutMap>;
/// Types implementing this Trait can draw on the terminal and receive events.
/// If a type wants to skip drawing if it has not changed anything, it can hold some flag in its

4
src/components/contacts.rs

@ -20,7 +20,7 @@
*/
use super::*;
use fnv::FnvHashMap;
use std::collections::HashMap;
mod contact_list;
@ -205,7 +205,7 @@ impl Component for ContactManager {
let fields = std::mem::replace(&mut self.form, FormWidget::default())
.collect()
.unwrap();
let fields: FnvHashMap<String, String> = fields
let fields: HashMap<String, String> = fields
.into_iter()
.map(|(s, v)| {
(

3
src/components/mail/listing.rs

@ -22,6 +22,7 @@
use super::*;
use crate::types::segment_tree::SegmentTree;
use smallvec::SmallVec;
use std::collections::{HashMap, HashSet};
use std::ops::{Deref, DerefMut};
mod conversations;
@ -1149,7 +1150,7 @@ impl Listing {
debug!("BUG: invalid area in print_account");
}
// Each entry and its index in the account
let mailboxes: FnvHashMap<MailboxHash, Mailbox> = context.accounts[a.index]
let mailboxes: HashMap<MailboxHash, Mailbox> = context.accounts[a.index]
.mailbox_entries
.iter()
.map(|(&hash, entry)| (hash, entry.ref_mailbox.clone()))

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

@ -54,15 +54,15 @@ pub struct CompactListing {
length: usize,
sort: (SortField, SortOrder),
subsort: (SortField, SortOrder),
all_threads: fnv::FnvHashSet<ThreadHash>,
order: FnvHashMap<ThreadHash, usize>,
all_threads: HashSet<ThreadHash>,
order: HashMap<ThreadHash, usize>,
/// Cache current view.
data_columns: DataColumns,
filter_term: String,
filtered_selection: Vec<ThreadHash>,
filtered_order: FnvHashMap<ThreadHash, usize>,
selection: FnvHashMap<ThreadHash, bool>,
filtered_order: HashMap<ThreadHash, usize>,
selection: HashMap<ThreadHash, bool>,
/// If we must redraw on next redraw event
dirty: bool,
force_draw: bool,
@ -661,12 +661,12 @@ impl CompactListing {
length: 0,
sort: (Default::default(), Default::default()),
subsort: (SortField::Date, SortOrder::Desc),
all_threads: fnv::FnvHashSet::default(),
order: FnvHashMap::default(),
all_threads: HashSet::default(),
order: HashMap::default(),
filter_term: String::new(),
filtered_selection: Vec::new(),
filtered_order: FnvHashMap::default(),
selection: FnvHashMap::default(),
filtered_order: HashMap::default(),
selection: HashMap::default(),
row_updates: SmallVec::new(),
data_columns: DataColumns::default(),
dirty: true,