pub struct ArrayStore {
pub entities: EntityTable,
/* private fields */
}Expand description
Storage for PostScript array element data.
Fields§
§entities: EntityTableImplementations§
Source§impl ArrayStore
impl ArrayStore
pub fn new() -> Self
Sourcepub fn allocated_objects(&self) -> usize
pub fn allocated_objects(&self) -> usize
Number of object slots handed out so far.
The backing arena only ever grows — nothing is reclaimed without a
restore — so this doubles as the store’s high-water mark. Useful for
asserting that a code path which evaluates PostScript repeatedly isn’t
allocating a fresh array per evaluation.
Sourcepub fn data_len(&self) -> usize
pub fn data_len(&self) -> usize
Release every object slot and entity from the given marks onward.
Used by restore to reclaim the objects a save level created. See
crate::entity_table::EntityTable::truncate for the safety argument
and the EntityId-reuse caveat.
Number of PsObject slots currently held.
Used for VM accounting; see crate::context::Context::vm_bytes.
Sourcepub fn data_capacity(&self) -> usize
pub fn data_capacity(&self) -> usize
Slots currently reserved, which is what the allocator actually holds.
VM accounting has to use this rather than the length. The backing
Vec grows geometrically, so a store holding just under the ceiling by
length asks the allocator for roughly twice that on its next growth —
which is how { 1000000 string pop } loop still aborted with a 16 GB
request after a length-based check had passed at 8 GB.
pub fn truncate_to(&mut self, data_len: usize, entity_len: usize)
Sourcepub fn allocate(&mut self, len: usize) -> EntityId
pub fn allocate(&mut self, len: usize) -> EntityId
Allocate len null-filled slots, returning an EntityId.
Sourcepub fn allocate_from(&mut self, items: &[PsObject]) -> EntityId
pub fn allocate_from(&mut self, items: &[PsObject]) -> EntityId
Allocate and copy items into the store.
Sourcepub fn allocate_from_with(
&mut self,
items: &[PsObject],
save_level: u16,
global: bool,
created_after_save: u32,
) -> EntityId
pub fn allocate_from_with( &mut self, items: &[PsObject], save_level: u16, global: bool, created_after_save: u32, ) -> EntityId
Allocate and copy items with a specific save level and global flag.
Sourcepub fn allocate_with(
&mut self,
len: usize,
save_level: u16,
global: bool,
created_after_save: u32,
) -> EntityId
pub fn allocate_with( &mut self, len: usize, save_level: u16, global: bool, created_after_save: u32, ) -> EntityId
Allocate with a specific save level and global flag.
Sourcepub fn iter_entities(&self) -> impl Iterator<Item = (EntityId, &[PsObject])>
pub fn iter_entities(&self) -> impl Iterator<Item = (EntityId, &[PsObject])>
Iterate every allocated array in this store as (EntityId, elements).
Used by the VM audit (see crate::vm_audit) to sweep global VM for
PLRM 3.7.2 violations. Sweeping the entity table rather than following
references catches arrays written through ArrayStore::get_mut, which
hands out &mut [PsObject] and so bypasses any per-store checkpoint.
Sourcepub fn get(&self, entity: EntityId, start: u32, len: u32) -> &[PsObject]
pub fn get(&self, entity: EntityId, start: u32, len: u32) -> &[PsObject]
Get a slice of array elements via entity table indirection.
Sourcepub fn get_mut(
&mut self,
entity: EntityId,
start: u32,
len: u32,
) -> &mut [PsObject]
pub fn get_mut( &mut self, entity: EntityId, start: u32, len: u32, ) -> &mut [PsObject]
Get a mutable slice of array elements via entity table indirection.
Sourcepub fn get_element(&self, entity: EntityId, index: u32) -> PsObject
pub fn get_element(&self, entity: EntityId, index: u32) -> PsObject
Get a single element.
Sourcepub fn set_element(&mut self, entity: EntityId, index: u32, obj: PsObject)
pub fn set_element(&mut self, entity: EntityId, index: u32, obj: PsObject)
Set a single element.
Sourcepub fn cow_copy(&mut self, entity: EntityId) -> EntityId
pub fn cow_copy(&mut self, entity: EntityId) -> EntityId
Copy entity data to a new region (for COW). Returns the new EntityId pointing at the backup. The original entity’s offset is updated to point at the fresh copy.
Sourcepub fn swap_offsets(&mut self, a: EntityId, b: EntityId)
pub fn swap_offsets(&mut self, a: EntityId, b: EntityId)
Swap offsets between two entities (used by restore).