enum CRef: separate from struct CBox and simplify but expand the API#1471
Merged
enum CRef: separate from struct CBox and simplify but expand the API#1471
enum CRef: separate from struct CBox and simplify but expand the API#1471Conversation
This allows other types, like `Vec<u8>`, `[u8; N]`, `&[u8]`, `Arc<[u8]>` instead of just `Box<[u8]>` (assuming `T = [u8]`). However, it requires an extra `Box` allocation and indirection. But the allocation is small and not very frequent, so it should be fine, and `CArc` stores a direct ptr, avoiding the extra indirection penalty (`CBox` is generally always accessed through `CArc` in `rav1d`).
…directly This simplifies a bunch of the APIs.
This avoids the extra `Box` and lets us make safety guarantees about each type's reference stability, which we depend on. For example, `Vec` doesn't have stable references (a wrapper than can't resize would, which we can add if needed).
randomPoison
approved these changes
Feb 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This does some API simplification for #1439 while also supporting other
impl AsReftypes. It separatesCReffromCBox.CBoxis the pure C abstraction over an owned C reference/"Box".CRefis anenumoverCBoxand other Rust-nativeimpl AsRefs. I tried usingdyn AsReffirst, but we make some safety guarantees about reference stability that we can't make about anyimpl AsRef, and that would force an extraBox. Moving thedyn AsRefone level higher toArc<dyn AsRef<T>>would be super nice, but in order to send theArcs through FFI boundaries, they can't wrap an unsized type, as we can't send unsized pointers over FFI boundaries (the ptr metadata API is still very unstable).Adding support for non
'static&Ts would be extremely useful and would allow us to eliminate a data copy, but that is much more tricky, as we'd have to thread the lifetime through a lot of places and probably rearrange some of theRav1dContext/Rav1dStateAPI.