(Clippy fixes across the board)
This commit is contained in:
parent
b315ea20a7
commit
637ac22a99
7 changed files with 61 additions and 69 deletions
|
@ -210,8 +210,8 @@ struct BenchResult {
|
||||||
|
|
||||||
impl BenchResult {
|
impl BenchResult {
|
||||||
pub fn new(codec: impl AsRef<str>, mut decode_sec: Vec<f64>, mut encode_sec: Vec<f64>) -> Self {
|
pub fn new(codec: impl AsRef<str>, mut decode_sec: Vec<f64>, mut encode_sec: Vec<f64>) -> Self {
|
||||||
decode_sec.sort_by(|a, b| a.partial_cmp(&b).unwrap_or(Ordering::Equal));
|
decode_sec.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
|
||||||
encode_sec.sort_by(|a, b| a.partial_cmp(&b).unwrap_or(Ordering::Equal));
|
encode_sec.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
|
||||||
let codec = codec.as_ref().into();
|
let codec = codec.as_ref().into();
|
||||||
Self { codec, decode_sec, encode_sec }
|
Self { codec, decode_sec, encode_sec }
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl Default for ColorSpace {
|
||||||
impl From<ColorSpace> for u8 {
|
impl From<ColorSpace> for u8 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(colorspace: ColorSpace) -> Self {
|
fn from(colorspace: ColorSpace) -> Self {
|
||||||
colorspace as u8
|
colorspace as Self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ use crate::header::Header;
|
||||||
use crate::pixel::{Pixel, SupportedChannels};
|
use crate::pixel::{Pixel, SupportedChannels};
|
||||||
use crate::utils::{cold, unlikely};
|
use crate::utils::{cold, unlikely};
|
||||||
|
|
||||||
|
const QOI_OP_INDEX_END: u8 = QOI_OP_INDEX | 0x3f;
|
||||||
|
const QOI_OP_RUN_END: u8 = QOI_OP_RUN | 0x3d; // <- note, 0x3d (not 0x3f)
|
||||||
|
const QOI_OP_DIFF_END: u8 = QOI_OP_DIFF | 0x3f;
|
||||||
|
const QOI_OP_LUMA_END: u8 = QOI_OP_LUMA | 0x3f;
|
||||||
|
|
||||||
pub fn qoi_decode_impl<const N: usize, const RGBA: bool>(
|
pub fn qoi_decode_impl<const N: usize, const RGBA: bool>(
|
||||||
data: &[u8], n_pixels: usize,
|
data: &[u8], n_pixels: usize,
|
||||||
) -> Result<Vec<u8>>
|
) -> Result<Vec<u8>>
|
||||||
|
@ -24,11 +29,6 @@ where
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const QOI_OP_INDEX_END: u8 = QOI_OP_INDEX | 0x3f;
|
|
||||||
const QOI_OP_RUN_END: u8 = QOI_OP_RUN | 0x3d; // <- note, 0x3d (not 0x3f)
|
|
||||||
const QOI_OP_DIFF_END: u8 = QOI_OP_DIFF | 0x3f;
|
|
||||||
const QOI_OP_LUMA_END: u8 = QOI_OP_LUMA | 0x3f;
|
|
||||||
|
|
||||||
let mut out = vec![0; n_pixels * N]; // unnecessary zero-init, but w/e
|
let mut out = vec![0; n_pixels * N]; // unnecessary zero-init, but w/e
|
||||||
let mut pixels = cast_slice_mut::<_, [u8; N]>(&mut out);
|
let mut pixels = cast_slice_mut::<_, [u8; N]>(&mut out);
|
||||||
let mut data = &data[QOI_HEADER_SIZE..];
|
let mut data = &data[QOI_HEADER_SIZE..];
|
||||||
|
@ -36,9 +36,7 @@ where
|
||||||
let mut index = [Pixel::<N>::new(); 256];
|
let mut index = [Pixel::<N>::new(); 256];
|
||||||
let mut px = Pixel::<N>::new().with_a(0xff);
|
let mut px = Pixel::<N>::new().with_a(0xff);
|
||||||
|
|
||||||
loop {
|
while let [px_out, ptail @ ..] = pixels {
|
||||||
match pixels {
|
|
||||||
[px_out, ptail @ ..] => {
|
|
||||||
pixels = ptail;
|
pixels = ptail;
|
||||||
match data {
|
match data {
|
||||||
[b1 @ QOI_OP_INDEX..=QOI_OP_INDEX_END, dtail @ ..] => {
|
[b1 @ QOI_OP_INDEX..=QOI_OP_INDEX_END, dtail @ ..] => {
|
||||||
|
@ -90,12 +88,6 @@ where
|
||||||
index[usize::from(px.hash_index())] = px;
|
index[usize::from(px.hash_index())] = px;
|
||||||
*px_out = px.into();
|
*px_out = px.into();
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
cold();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,12 @@ impl<'a> WriteBuf<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn len(&self) -> usize {
|
pub const fn len(&self) -> usize {
|
||||||
self.buf.len()
|
self.buf.len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
fn qoi_encode_impl<const CHANNELS: usize>(
|
fn qoi_encode_impl<const CHANNELS: usize>(
|
||||||
out: &mut [u8], data: &[u8], width: u32, height: u32, colorspace: ColorSpace,
|
out: &mut [u8], data: &[u8], width: u32, height: u32, colorspace: ColorSpace,
|
||||||
) -> Result<usize>
|
) -> Result<usize>
|
||||||
|
|
|
@ -26,6 +26,7 @@ impl Default for Header {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
const fn u32_to_be(v: u32) -> [u8; 4] {
|
const fn u32_to_be(v: u32) -> [u8; 4] {
|
||||||
[
|
[
|
||||||
((0xff00_0000 & v) >> 24) as u8,
|
((0xff00_0000 & v) >> 24) as u8,
|
||||||
|
@ -47,7 +48,7 @@ impl Header {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_colorspace(mut self, colorspace: ColorSpace) -> Self {
|
pub const fn with_colorspace(mut self, colorspace: ColorSpace) -> Self {
|
||||||
self.colorspace = colorspace;
|
self.colorspace = colorspace;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
|
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::inline_always,
|
clippy::inline_always,
|
||||||
clippy::struct_excessive_bools,
|
|
||||||
clippy::fn_params_excessive_bools,
|
|
||||||
clippy::similar_names,
|
clippy::similar_names,
|
||||||
clippy::missing_errors_doc,
|
clippy::missing_errors_doc,
|
||||||
clippy::must_use_candidate,
|
clippy::must_use_candidate,
|
||||||
clippy::never_loop,
|
clippy::module_name_repetitions,
|
||||||
clippy::module_name_repetitions
|
clippy::cargo_common_metadata
|
||||||
)]
|
)]
|
||||||
|
|
||||||
mod colorspace;
|
mod colorspace;
|
||||||
|
|
|
@ -6,7 +6,7 @@ pub const fn cold() {}
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub const fn likely(b: bool) -> bool {
|
pub const fn likely(b: bool) -> bool {
|
||||||
if !b {
|
if !b {
|
||||||
cold()
|
cold();
|
||||||
}
|
}
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ pub const fn likely(b: bool) -> bool {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub const fn unlikely(b: bool) -> bool {
|
pub const fn unlikely(b: bool) -> bool {
|
||||||
if b {
|
if b {
|
||||||
cold()
|
cold();
|
||||||
}
|
}
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue