Use perfrect hash map for new implementation of dc_msg_guess_msgtype_from_suffix

This commit is contained in:
Dmitry Bogatov
2019-08-14 18:14:58 +00:00
committed by holger krekel
parent 5917d05305
commit 6beea86df7
4 changed files with 230 additions and 205 deletions

426
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,7 @@ pgp = { version = "0.2", default-features = false }
hex = "0.3.2"
sha2 = "0.8.0"
rand = "0.6.5"
maplit = "1.0.1"
phf = { git = "https://github.com/sfackler/rust-phf", rev = "0d00821", features = ["macros"] }
smallvec = "0.6.9"
reqwest = "0.9.15"
num-derive = "0.2.5"

View File

@@ -15,6 +15,7 @@ use crate::sql;
use crate::stock::StockMessage;
use crate::types::*;
use crate::x::*;
use phf::phf_map;
use std::ptr;
/* * the structure behind dc_msg_t */
@@ -286,7 +287,7 @@ pub unsafe fn dc_msg_get_filemime(msg: *const dc_msg_t) -> *mut libc::c_char {
}
pub fn dc_msg_guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
let known = hashmap! {
static KNOWN: phf::Map<&'static str, (Viewtype, &'static str)> = phf_map! {
"mp3" => (Viewtype::Audio, "audio/mpeg"),
"aac" => (Viewtype::Audio, "audio/aac"),
"mp4" => (Viewtype::Video, "video/mp4"),
@@ -300,7 +301,7 @@ pub fn dc_msg_guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)>
};
let extension = path.extension()?.to_str()?;
known.get(extension).map(|x| *x)
KNOWN.get(extension).map(|x| *x)
}
pub unsafe fn dc_msg_get_file(msg: *const dc_msg_t) -> *mut libc::c_char {

View File

@@ -16,8 +16,6 @@ extern crate rusqlite;
extern crate strum;
#[macro_use]
extern crate strum_macros;
#[macro_use]
extern crate maplit;
#[macro_use]
mod log;