use git_zero_core::{ObjectId, RevisionLimits, ValidationMetadata};
pub struct RevisionStorage<'a> {
pub selection: SelectionStorage<'a>,
pub state: &'a mut [u8],
pub limits: RevisionLimits,
}
impl RevisionStorage<'_> {
pub fn reborrow(&mut self) -> RevisionStorage<'_> {
RevisionStorage {
selection: self.selection.reborrow(),
state: self.state,
limits: self.limits,
}
}
}
pub struct RevisionBuffers<
const WANTS: usize,
const OBJECTS: usize,
const READ: usize,
const PARSE: usize,
> {
selection: SelectionBuffers<WANTS, OBJECTS, READ, PARSE>,
state: [u8; OBJECTS],
}
impl<const WANTS: usize, const OBJECTS: usize, const READ: usize, const PARSE: usize>
RevisionBuffers<WANTS, OBJECTS, READ, PARSE>
{
pub const fn new() -> Self {
Self {
selection: SelectionBuffers::new(),
state: [0; OBJECTS],
}
}
pub fn storage(
&mut self,
graph_read_limit: u64,
limits: RevisionLimits,
) -> RevisionStorage<'_> {
RevisionStorage {
selection: self.selection.storage(graph_read_limit),
state: &mut self.state,
limits,
}
}
pub const fn storage_bytes(&self) -> usize {
core::mem::size_of::<Self>()
}
}
impl<const WANTS: usize, const OBJECTS: usize, const READ: usize, const PARSE: usize> Default
for RevisionBuffers<WANTS, OBJECTS, READ, PARSE>
{
fn default() -> Self {
Self::new()
}
}
pub struct SelectionStorage<'a> {
pub wants: &'a mut [ObjectId],
pub objects: &'a mut [Option<ValidationMetadata>],
pub indices: &'a mut [usize],
pub read: &'a mut [u8],
pub parse: &'a mut [u8],
pub graph_read_limit: u64,
}
impl SelectionStorage<'_> {
pub fn reborrow(&mut self) -> SelectionStorage<'_> {
SelectionStorage {
wants: self.wants,
objects: self.objects,
indices: self.indices,
read: self.read,
parse: self.parse,
graph_read_limit: self.graph_read_limit,
}
}
}
pub struct SelectionBuffers<
const WANTS: usize,
const OBJECTS: usize,
const READ: usize,
const PARSE: usize,
> {
wants: [ObjectId; WANTS],
objects: [Option<ValidationMetadata>; OBJECTS],
indices: [usize; OBJECTS],
read: [u8; READ],
parse: [u8; PARSE],
}
impl<const WANTS: usize, const OBJECTS: usize, const READ: usize, const PARSE: usize>
SelectionBuffers<WANTS, OBJECTS, READ, PARSE>
{
pub const fn new() -> Self {
Self {
wants: [ObjectId::Sha1([0; 20]); WANTS],
objects: [None; OBJECTS],
indices: [0; OBJECTS],
read: [0; READ],
parse: [0; PARSE],
}
}
pub fn storage(&mut self, graph_read_limit: u64) -> SelectionStorage<'_> {
SelectionStorage {
wants: &mut self.wants,
objects: &mut self.objects,
indices: &mut self.indices,
read: &mut self.read,
parse: &mut self.parse,
graph_read_limit,
}
}
pub const fn want_capacity(&self) -> usize {
WANTS
}
pub const fn object_capacity(&self) -> usize {
OBJECTS
}
pub const fn read_capacity(&self) -> usize {
READ
}
pub const fn parse_capacity(&self) -> usize {
PARSE
}
pub const fn storage_bytes(&self) -> usize {
core::mem::size_of::<Self>()
}
}
impl<const WANTS: usize, const OBJECTS: usize, const READ: usize, const PARSE: usize> Default
for SelectionBuffers<WANTS, OBJECTS, READ, PARSE>
{
fn default() -> Self {
Self::new()
}
}