MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / alloc_for_slice

Method alloc_for_slice

crates/table/src/page.rs:630–638  ·  view source on GitHub ↗

Allocates and stores `slice` as a linked-list of granules in the var-len storage of the page. Returns a [`VarLenRef`] pointing to the head of that list, and a boolean `in_blob` for whether the allocation is a `BlobHash` and the `slice` must be inserted into the large-blob store. # Safety post-requirements The following are the safety *post-requirements* of calling this method. That is, this met

(&mut self, slice: &[u8])

Source from the content-addressed store, hash-verified

628 /// has an initialized header and a data section initialized to at least
629 /// as many bytes as claimed by the header.
630 pub fn alloc_for_slice(&mut self, slice: &[u8]) -> Result<(VarLenRef, bool), Error> {
631 let obj_len = slice.len();
632 // Safety post-requirement 2. of `alloc_for_obj_common` is already satisfied
633 // as `chunks(slice)` will return sub-slices where the sum is `obj_len`.
634 // Moreover, we initialize each granule already with the right data and length.
635 // The requirement 1. is forwarded to the caller.
636 let chunks = |_| VarLenGranule::chunks(slice).rev().map(|c| (c, c.len()));
637 self.alloc_for_obj_common(obj_len, chunks)
638 }
639
640 /// Allocates for `obj_len` bytes as a linked-list of granules
641 /// in the var-len storage of the page.

Callers 2

write_stringMethod · 0.80
insert_rowMethod · 0.80

Calls 3

alloc_for_obj_commonMethod · 0.80
lenMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected