Skip to content

Commit 3f55807

Browse files
authored
enum TileStateRef: Manual impl Atom instead of #[derive(Atom)]ing it, since the derive may panic (#1247)
* Part of #1180. It is more optimal to `.unwrap_or_default()`, which is a `cmov`, rather than branching to a panic message, which bloats the code a lot. This reduces stack usage in `fn decode_coefs` by 64 bytes, from 296 to 232.
2 parents d98a9c0 + 951d69d commit 3f55807

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/internal.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ use std::sync::atomic::Ordering;
104104
use std::sync::Arc;
105105
use std::sync::OnceLock;
106106
use std::thread::JoinHandle;
107+
use strum::FromRepr;
107108
use zerocopy::AsBytes;
108109
use zerocopy::FromBytes;
109110
use zerocopy::FromZeroes;
@@ -907,14 +908,26 @@ pub struct Rav1dTileState {
907908
pub lr_ref: RwLock<[Av1RestorationUnit; 3]>,
908909
}
909910

910-
#[derive(Clone, Copy, Default, Atom)]
911+
#[derive(Clone, Copy, Default, FromRepr)]
911912
#[repr(u8)]
912913
pub enum TileStateRef {
913914
#[default]
914915
Frame,
915916
Local,
916917
}
917918

919+
impl Atom for TileStateRef {
920+
type Repr = u8;
921+
922+
fn pack(self) -> Self::Repr {
923+
self as u8
924+
}
925+
926+
fn unpack(src: Self::Repr) -> Self {
927+
Self::from_repr(src).unwrap_or_default()
928+
}
929+
}
930+
918931
/// Array of 32 * 32 coef elements (either `i16` or `i32`).
919932
#[derive(FromZeroes)]
920933
#[repr(align(64))]

0 commit comments

Comments
 (0)