simplify InferDb custom mimetypes

using `buf.starts_with(b"\xAB\xCD")` instead of `buf[0] == 0xAB && buf[1] == 0xCD` is shorter, easier to read, removes the need for the `buf.len() > xyz` check, and actually compiles to (much) less assembly:
https://godbolt.org/z/M7GePGn1T

isn't that just lovely
This commit is contained in:
Lynne Megido 2021-09-29 23:29:21 +10:00
parent db80955f24
commit 47d94cf27b
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -18,6 +18,8 @@ cfg_if! {
db: infer::Infer,
}
// TODO: msi
fn open_document_check(buf: &[u8], kind: &str) -> bool {
let mime = format!("application/vnd.oasis.opendocument.{}", kind);
let mime = mime.as_bytes();
@ -48,15 +50,7 @@ cfg_if! {
info.add("audio/x-aiff", "aiff", |buf| {
// as added by https://github.com/bojand/infer/pull/48/files
// this should be removed when (if) that PR is accepted
buf.len() > 11
&& buf[0] == 0x46
&& buf[1] == 0x4F
&& buf[2] == 0x52
&& buf[3] == 0x4D
&& buf[8] == 0x41
&& buf[9] == 0x49
&& buf[10] == 0x46
&& buf[11] == 0x46
buf.starts_with(b"\x46\x4f\x52\x4d\x41\x49\x46\x46")
});
info.add("image/svg+xml", "svg", |buf| {