Skip to content

Commit

Permalink
use Cow for VariationModel that might be either borrowed or owned
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed May 8, 2024
1 parent 75cf0de commit 326a91c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Feature binary compilation.

use std::{
borrow::Cow,
cell::RefCell,
collections::{HashMap, HashSet},
ffi::{OsStr, OsString},
Expand Down Expand Up @@ -158,16 +159,16 @@ pub(crate) fn resolve_variable_metric<'a>(

// Try to reuse the global model, or make a new sub-model only with the locations we
// are asked for so we can support sparseness
let local_model: VariationModel;
let var_model = if locations == global_locations {
&static_metadata.variation_model
let var_model: Cow<'_, VariationModel> = if locations == global_locations {
Cow::Borrowed(&static_metadata.variation_model)
} else {
local_model = VariationModel::new(
locations.into_iter().cloned().collect(),
static_metadata.axes.clone(),
Cow::Owned(
VariationModel::new(
locations.into_iter().cloned().collect(),
static_metadata.axes.clone(),
)
.unwrap(),
)
.unwrap();
&local_model
};

let raw_deltas: Vec<_> = var_model
Expand Down Expand Up @@ -348,16 +349,16 @@ impl<'a> VariationInfo for FeaVariationInfo<'a> {

// Try to reuse the global model, or make a new sub-model only with the locations we
// are asked for so we can support sparseness
let local_model: VariationModel;
let var_model = if locations == global_locations {
&self.static_metadata.variation_model
let var_model: Cow<'_, VariationModel> = if locations == global_locations {
Cow::Borrowed(&self.static_metadata.variation_model)
} else {
local_model = VariationModel::new(
locations.into_iter().cloned().collect(),
self.static_metadata.axes.clone(),
Cow::Owned(
VariationModel::new(
locations.into_iter().cloned().collect(),
self.static_metadata.axes.clone(),
)
.unwrap(),
)
.unwrap();
&local_model
};

// Only 1 value per region for our input
Expand Down

0 comments on commit 326a91c

Please sign in to comment.