Struct OwnedRow
pub struct OwnedRow { /* private fields */ }Expand description
An owned row: an index-addressed, immutable, cheaply-clonable value sequence,
stored as one flat allocation (205-FLAT-ROW-SINGLE-BUFFER-DESIGN.md).
Cloning a row into an overlay / the view / a heap is a refcount bump, not a
deep copy (shared-row aliasing is pervasive) — exactly as when this was
Arc<[OwnedValue]>, but the cells now live inline in the row’s own buffer
(no per-Str-cell Arc<str> block), so materializing a row is one
allocation instead of 2 + k_text.
Layout (all integers little-endian):
[0..4) n: u32 cell count
[4..4+9n) directory, 9 bytes per cell: [tag u8][payload 8B]
Absent/Null: payload unused Bool: payload[0]
Int: i64 Float: f64 bits
Str/Json: [off u32][len u32] (absolute into the buffer)
[4+9n..) Str/Json bytes, concatenated in cell orderCells are read as borrowed Value<'_>s via OwnedRow::col — Str/Json
borrow the row’s own buffer zero-copy. Text bytes are UTF-8-validated at
construction (the same eager timing as the old per-cell
Value::try_to_owned), so readers never re-validate.
Implementations§
§impl OwnedRow
impl OwnedRow
pub fn is_empty(&self) -> bool
pub fn col(&self, c: usize) -> Value<'_>
pub fn col(&self, c: usize) -> Value<'_>
Read cell c, zero-copy. Panics if c is out of range — the same
contract as the old slice index (ColIds are resolved against the schema
at build time, so an out-of-range read is a builder bug).
#[inline(always)] + the out-of-line panic are load-bearing: this is the
cell accessor inside compare_rows, i.e. inside every btree node compare
on the write path. One fused 9-byte cell slice (a single bounds check)
instead of separate tag/payload indexing keeps it a handful of
instructions.
pub fn get(&self, c: usize) -> Option<Value<'_>>
pub fn get(&self, c: usize) -> Option<Value<'_>>
Read cell c, or None if out of range (the tolerant peer of
OwnedRow::col — the wasm marshal reads short/projected rows with it).
pub fn cells(&self) -> impl ExactSizeIterator
pub fn cells(&self) -> impl ExactSizeIterator
Iterate the cells as borrowed Value<'_>s (replaces .iter() over the
old &[OwnedValue] view).
pub fn ptr_eq(a: &OwnedRow, b: &OwnedRow) -> bool
pub fn ptr_eq(a: &OwnedRow, b: &OwnedRow) -> bool
Row identity (not equality): do two rows share the same buffer? The
btree’s COW-refresh and structural-diff fast paths use this exactly as
they used Arc::ptr_eq on the old Arc<[OwnedValue]>.
pub fn byte_len(&self) -> usize
pub fn byte_len(&self) -> usize
The size of the row’s single heap buffer in bytes (header + directory +
text region) — the row’s entire heap footprint besides the Arc header.
Memory accounting (e.g. rindle-loadgen) reads this instead of modeling
per-cell blocks, which no longer exist.
pub fn empty() -> OwnedRow
pub fn empty() -> OwnedRow
The shared zero-column row (ghost/placeholder entries). O(1), allocates once per process.
pub fn to_value_vec(&self) -> Vec<OwnedValue>
pub fn to_value_vec(&self) -> Vec<OwnedValue>
Materialize every cell as an OwnedValue (the wire / compatibility
escape — allocates per Str/Json cell).
pub fn from_owned_cells(cells: &[OwnedValue]) -> OwnedRow
pub fn from_owned_cells(cells: &[OwnedValue]) -> OwnedRow
Build a row from already-owned cells. Infallible: an
OwnedValue::Str/Json is Arc<str>, so its bytes
are valid UTF-8 by construction — no validation pass.
pub fn try_from_row_ref<R>(r: &R) -> Result<OwnedRow, RindleError>
pub fn try_from_row_ref<R>(r: &R) -> Result<OwnedRow, RindleError>
The leaf-boundary constructor: materialize a borrowed row (e.g. the
SQLite step buffer) into one flat allocation, validating Str/Json
UTF-8 exactly once — the same eager timing as the old per-cell
Value::try_to_owned, but with no per-cell allocation. Errors surface
before the row allocates.
Trait Implementations§
§impl RowRef for &OwnedRow
THE canonical owned→borrowed bridge for the memory backend. Vending a
&OwnedRow (rather than a &[OwnedValue] slice) is what makes
to_owned_row an O(1) Arc bump instead of a deep copy — folding the btree
spike’s current_arc escape hatch (04 OQ-2) into the shared trait. The
BTreeCursor sets type Row<'a> = &'a OwnedRow and gets owning-at-the-node
-boundary for free.
impl RowRef for &OwnedRow
THE canonical owned→borrowed bridge for the memory backend. Vending a
&OwnedRow (rather than a &[OwnedValue] slice) is what makes
to_owned_row an O(1) Arc bump instead of a deep copy — folding the btree
spike’s current_arc escape hatch (04 OQ-2) into the shared trait. The
BTreeCursor sets type Row<'a> = &'a OwnedRow and gets owning-at-the-node
-boundary for free.
§fn to_owned_row(&self) -> OwnedRow
fn to_owned_row(&self) -> OwnedRow
Rc memory backend this is an
O(1) Arc bump (the impl on &OwnedRow below); for the SQLite leaf it
is the one forced per-row copy out of the step buffer (sqlite.rs).fn is_empty(&self) -> bool
§fn try_to_owned_row(&self) -> Result<OwnedRow, RindleError>
fn try_to_owned_row(&self) -> Result<OwnedRow, RindleError>
Arc bump; SQLite rows override this to
surface invalid text/json as RindleError instead of panicking.