Browse Source

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
master
Lynne Megido 2 months ago
parent
commit
47d94cf27b
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
  1. 12
      src/mime_db.rs

12
src/mime_db.rs

@ -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| {

Loading…
Cancel
Save