Skip to main content

HeaderTypeCache

Trait HeaderTypeCache 

Source
pub trait HeaderTypeCache {
    // Required methods
    fn get(&self, pack_offset: u64) -> Option<(ObjectType, u64)>;
    fn put(&mut self, pack_offset: u64, header: (ObjectType, u64));
}
Expand description

Memo of pack offset -> resolved header (end-of-chain type, result size) for the cat-file --batch-check header fast path.

Without it, resolving the type of an ofs-delta walks the whole delta chain to its base on every header read, re-inflating each link’s leading varints from scratch — so reading every object in a deeply-deltified pack costs O(objects x chain-depth) and goes super-linear (sley#26). Two reuses fall out of memoizing offset -> (type, size):

  • a chain’s end-of-chain type is resolved at most once, so later objects on the same chain skip the walk; and
  • a repeated lookup of the same object (common in batch input) returns from the memo without re-inflating its delta header at all.

The size stored is the object’s final (inflated) result size — read from its own pack/delta header, never by materializing the body.

Required Methods§

Source

fn get(&self, pack_offset: u64) -> Option<(ObjectType, u64)>

The previously resolved header at pack_offset, if any.

Source

fn put(&mut self, pack_offset: u64, header: (ObjectType, u64))

Record the resolved header at pack_offset for reuse by later reads.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§