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

Method alloc_for_len

crates/table/src/page.rs:575–594  ·  view source on GitHub ↗

Allocates a linked-list of granules, in the var-len storage of the page, for a var-len object of `obj_len` bytes. Returns a [`VarLenRef`] pointing to the head of that list, and a boolean `in_blob` for whether the allocation is a `BlobHash` and the object must be inserted into the large-blob store. The length of each granule is set, but no data is written to any granule. Thus, the caller must pro

(&mut self, obj_len: usize)

Source from the content-addressed store, hash-verified

573 /// 2. The caller must initialize each granule with data for the claimed length
574 /// of the granule's data.
575 pub fn alloc_for_len(&mut self, obj_len: usize) -> Result<(VarLenRef, bool), Error> {
576 // Safety post-requirements of `alloc_for_obj_common`:
577 // 1. caller promised they will be satisfied.
578 // 2a. already satisfied as the closure below returns all the summands of `obj_len`.
579 // 2b. caller promised in 2. that they will satisfy this.
580 self.alloc_for_obj_common(obj_len, |req_granules| {
581 let rem = obj_len % VarLenGranule::DATA_SIZE;
582 (0..req_granules).map(move |rev_idx| {
583 let len = if rev_idx == 0 && rem != 0 {
584 // The first allocated granule will be the last in the list.
585 // Thus, `rev_idx == 0` is the last element and might not take up a full granule.
586 rem
587 } else {
588 VarLenGranule::DATA_SIZE
589 };
590 // Caller will initialize the granule's data for `len` bytes.
591 (<&[u8]>::default(), len)
592 })
593 })
594 }
595
596 /// Returns an iterator over all offsets of the `VarLenGranule`s of the var-len object
597 /// that has its first granule at offset `first_granule`.

Callers 1

write_av_bsatnMethod · 0.80

Calls 2

alloc_for_obj_commonMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected