Struct CowSlice

Source
pub struct CowSlice<'a> {
    data: &'a [i32],
    data_mut: &'a mut [i32],
    use_mut: bool,
}
Expand description

Backing store for the CVT and storage area.

The CVT and storage area are initialized in the control value program with values that are relevant to a particular size and hinting configuration. However, some fonts contain code in glyph programs that write to these buffers. Any modifications made in a glyph program should not affect future glyphs and thus should not persist beyond execution of that program. To solve this problem, a copy of the buffer is made on the first write in a glyph program and all changes are discarded on completion.

For more context, see https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/23

§Implementation notes

The current implementation defers the copy but not the allocation. This is to support the guarantee of no heap allocation when operating on user provided memory. Investigation of hinted Noto fonts suggests that writing to CVT/Storage in glyph programs is common for ttfautohinted fonts so the speculative allocation is likely worthwhile.

Fields§

§data: &'a [i32]§data_mut: &'a mut [i32]§use_mut: bool

True if we’ve initialized the mutable slice

Implementations§

Source§

impl<'a> CowSlice<'a>

Source

pub fn new( data: &'a [i32], data_mut: &'a mut [i32], ) -> Result<Self, CowSliceSizeMismatchError>

Creates a new copy-on-write slice with the given buffers.

The data buffer is expected to contain the initial data and the content of data_mut is ignored unless the set method is called in which case a copy will be made from data to data_mut and the mutable buffer will be used for all further access.

Returns CowSliceSizeMismatchError if data.len() != data_mut.len().

Source

pub fn new_mut(data_mut: &'a mut [i32]) -> Self

Creates a new copy-on-write slice with the given mutable buffer.

This avoids an extra copy and allocation in contexts where the data is already assumed to be mutable (i.e. when executing fpgm and prep programs).

Source

pub fn get(&self, index: usize) -> Option<i32>

Returns the value at the given index.

If mutable data has been initialized, reads from that buffer. Otherwise reads from the immutable buffer.

Source

pub fn set(&mut self, index: usize, value: i32) -> Option<()>

Writes a value to the given index.

If the mutable buffer hasn’t been initialized, first performs a full buffer copy.

Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl<'a> From<CowSlice<'a>> for Cvt<'a>

Source§

fn from(value: CowSlice<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<CowSlice<'a>> for Storage<'a>

Source§

fn from(value: CowSlice<'a>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for CowSlice<'a>

§

impl<'a> RefUnwindSafe for CowSlice<'a>

§

impl<'a> Send for CowSlice<'a>

§

impl<'a> Sync for CowSlice<'a>

§

impl<'a> Unpin for CowSlice<'a>

§

impl<'a> !UnwindSafe for CowSlice<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.