mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
Use perfrect hash map for new implementation of dc_msg_guess_msgtype_from_suffix
This commit is contained in:
committed by
holger krekel
parent
5917d05305
commit
6beea86df7
426
Cargo.lock
generated
426
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ pgp = { version = "0.2", default-features = false }
|
|||||||
hex = "0.3.2"
|
hex = "0.3.2"
|
||||||
sha2 = "0.8.0"
|
sha2 = "0.8.0"
|
||||||
rand = "0.6.5"
|
rand = "0.6.5"
|
||||||
maplit = "1.0.1"
|
phf = { git = "https://github.com/sfackler/rust-phf", rev = "0d00821", features = ["macros"] }
|
||||||
smallvec = "0.6.9"
|
smallvec = "0.6.9"
|
||||||
reqwest = "0.9.15"
|
reqwest = "0.9.15"
|
||||||
num-derive = "0.2.5"
|
num-derive = "0.2.5"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use crate::sql;
|
|||||||
use crate::stock::StockMessage;
|
use crate::stock::StockMessage;
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use crate::x::*;
|
use crate::x::*;
|
||||||
|
use phf::phf_map;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
/* * the structure behind dc_msg_t */
|
/* * 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)> {
|
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"),
|
"mp3" => (Viewtype::Audio, "audio/mpeg"),
|
||||||
"aac" => (Viewtype::Audio, "audio/aac"),
|
"aac" => (Viewtype::Audio, "audio/aac"),
|
||||||
"mp4" => (Viewtype::Video, "video/mp4"),
|
"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()?;
|
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 {
|
pub unsafe fn dc_msg_get_file(msg: *const dc_msg_t) -> *mut libc::c_char {
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ extern crate rusqlite;
|
|||||||
extern crate strum;
|
extern crate strum;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate strum_macros;
|
extern crate strum_macros;
|
||||||
#[macro_use]
|
|
||||||
extern crate maplit;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod log;
|
mod log;
|
||||||
|
|||||||
Reference in New Issue
Block a user