Skip to content

Commit

Permalink
Merge pull request #573 from googlefonts/go_faster
Browse files Browse the repository at this point in the history
Remove Access::Custom; it forces table scans to figure out what can run
  • Loading branch information
rsheeter authored Dec 6, 2023
2 parents 626c77f + 4f787a9 commit 8991d75
Show file tree
Hide file tree
Showing 26 changed files with 792 additions and 470 deletions.
2 changes: 1 addition & 1 deletion fontbe/src/avar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Work<Context, AnyWorkId, Error> for AvarWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::One(FeWorkId::StaticMetadata.into())
Access::Variant(AnyWorkId::Fe(FeWorkId::StaticMetadata))
}

/// Generate [avar](https://learn.microsoft.com/en-us/typography/opentype/spec/avar)
Expand Down
17 changes: 8 additions & 9 deletions fontbe/src/cmap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Generates a [cmap](https://learn.microsoft.com/en-us/typography/opentype/spec/cmap) table.
use std::sync::Arc;

use fontdrasil::orchestration::{Access, Work};
use fontdrasil::{
orchestration::{Access, AccessBuilder, Work},
types::GlyphName,
};
use fontir::orchestration::WorkId as FeWorkId;

use write_fonts::{tables::cmap::Cmap, types::GlyphId};
Expand All @@ -25,12 +26,10 @@ impl Work<Context, AnyWorkId, Error> for CmapWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Fe(FeWorkId::GlyphOrder) | AnyWorkId::Fe(FeWorkId::Glyph(..))
)
}))
AccessBuilder::new()
.variant(FeWorkId::GlyphOrder)
.variant(FeWorkId::Glyph(GlyphName::NOTDEF))
.build()
}

/// Generate [cmap](https://learn.microsoft.com/en-us/typography/opentype/spec/cmap)
Expand Down
18 changes: 9 additions & 9 deletions fontbe/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{
cell::RefCell,
collections::{BTreeMap, HashMap, HashSet},
collections::{BTreeMap, HashMap},
error::Error as StdError,
ffi::{OsStr, OsString},
fmt::Display,
Expand All @@ -28,7 +28,7 @@ use fontir::{

use fontdrasil::{
coords::NormalizedLocation,
orchestration::{Access, Work},
orchestration::{Access, AccessBuilder, Work},
types::Axis,
};
use write_fonts::{
Expand Down Expand Up @@ -438,13 +438,13 @@ impl Work<Context, AnyWorkId, Error> for FeatureWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Set(HashSet::from([
AnyWorkId::Fe(FeWorkId::GlyphOrder),
AnyWorkId::Fe(FeWorkId::StaticMetadata),
AnyWorkId::Fe(FeWorkId::Features),
AnyWorkId::Be(WorkId::Kerning),
AnyWorkId::Be(WorkId::Marks),
]))
AccessBuilder::new()
.variant(FeWorkId::GlyphOrder)
.variant(FeWorkId::StaticMetadata)
.variant(FeWorkId::Features)
.variant(WorkId::Kerning)
.variant(WorkId::Marks)
.build()
}

fn also_completes(&self) -> Vec<AnyWorkId> {
Expand Down
48 changes: 23 additions & 25 deletions fontbe/src/font.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Merge tables into a font
use std::collections::HashSet;

use fontdrasil::orchestration::{Access, Work};
use fontdrasil::orchestration::{Access, AccessBuilder, Work};
use fontir::orchestration::WorkId as FeWorkId;
use log::debug;
use write_fonts::{
Expand Down Expand Up @@ -110,28 +108,28 @@ impl Work<Context, AnyWorkId, Error> for FontWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Set(HashSet::from([
WorkId::Avar.into(),
WorkId::Cmap.into(),
WorkId::Fvar.into(),
WorkId::Head.into(),
WorkId::Hhea.into(),
WorkId::Hmtx.into(),
WorkId::Glyf.into(),
WorkId::Gpos.into(),
WorkId::Gsub.into(),
WorkId::Gdef.into(),
WorkId::Gvar.into(),
WorkId::Loca.into(),
WorkId::Maxp.into(),
WorkId::Name.into(),
WorkId::Os2.into(),
WorkId::Post.into(),
WorkId::Stat.into(),
WorkId::Hvar.into(),
FeWorkId::StaticMetadata.into(),
WorkId::LocaFormat.into(),
]))
AccessBuilder::new()
.variant(WorkId::Avar)
.variant(WorkId::Cmap)
.variant(WorkId::Fvar)
.variant(WorkId::Head)
.variant(WorkId::Hhea)
.variant(WorkId::Hmtx)
.variant(WorkId::Glyf)
.variant(WorkId::Gpos)
.variant(WorkId::Gsub)
.variant(WorkId::Gdef)
.variant(WorkId::Gvar)
.variant(WorkId::Loca)
.variant(WorkId::Maxp)
.variant(WorkId::Name)
.variant(WorkId::Os2)
.variant(WorkId::Post)
.variant(WorkId::Stat)
.variant(WorkId::Hvar)
.variant(WorkId::LocaFormat)
.variant(FeWorkId::StaticMetadata)
.build()
}

/// Glue binary tables into a font
Expand Down
2 changes: 1 addition & 1 deletion fontbe/src/fvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Work<Context, AnyWorkId, Error> for FvarWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::One(FeWorkId::StaticMetadata.into())
Access::Variant(AnyWorkId::Fe(FeWorkId::StaticMetadata))
}

/// Generate [fvar](https://learn.microsoft.com/en-us/typography/opentype/spec/fvar)
Expand Down
43 changes: 17 additions & 26 deletions fontbe/src/glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
//! Each glyph is built in isolation and then the fragments are collected
//! and glued together to form a final table.
use std::{
collections::{BTreeSet, HashMap, HashSet},
sync::Arc,
};
use std::collections::{BTreeSet, HashMap, HashSet};

use fontdrasil::{
coords::{Location, NormalizedCoord, NormalizedLocation},
orchestration::{Access, Work},
orchestration::{Access, AccessBuilder, Work},
types::GlyphName,
};
use fontir::{
Expand Down Expand Up @@ -324,10 +321,10 @@ impl Work<Context, AnyWorkId, Error> for GlyphWork {
}

fn write_access(&self) -> Access<AnyWorkId> {
Access::Set(HashSet::from([
WorkId::GlyfFragment(self.glyph_name.clone()).into(),
WorkId::GvarFragment(self.glyph_name.clone()).into(),
]))
AccessBuilder::new()
.specific_instance(WorkId::GlyfFragment(self.glyph_name.clone()))
.specific_instance(WorkId::GvarFragment(self.glyph_name.clone()))
.build()
}

fn also_completes(&self) -> Vec<AnyWorkId> {
Expand Down Expand Up @@ -853,26 +850,20 @@ impl Work<Context, AnyWorkId, Error> for GlyfLocaWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Fe(FeWorkId::StaticMetadata)
| AnyWorkId::Fe(FeWorkId::GlyphOrder)
| AnyWorkId::Be(WorkId::GlyfFragment(..))
)
}))
AccessBuilder::new()
.variant(FeWorkId::StaticMetadata)
.variant(FeWorkId::GlyphOrder)
.variant(WorkId::GlyfFragment(GlyphName::NOTDEF))
.build()
}

fn write_access(&self) -> Access<AnyWorkId> {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Be(WorkId::Glyf)
| AnyWorkId::Be(WorkId::Loca)
| AnyWorkId::Be(WorkId::LocaFormat)
| AnyWorkId::Be(WorkId::GlyfFragment(..))
)
}))
AccessBuilder::new()
.variant(AnyWorkId::Be(WorkId::Glyf))
.variant(AnyWorkId::Be(WorkId::Loca))
.variant(AnyWorkId::Be(WorkId::LocaFormat))
.variant(WorkId::GlyfFragment(GlyphName::NOTDEF))
.build()
}

fn also_completes(&self) -> Vec<AnyWorkId> {
Expand Down
17 changes: 6 additions & 11 deletions fontbe/src/gvar.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Generates a [gvar](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar) table.
use std::sync::Arc;

use fontdrasil::{
orchestration::{Access, Work},
orchestration::{Access, AccessBuilder, Work},
types::GlyphName,
};
use fontir::{ir::GlyphOrder, orchestration::WorkId as FeWorkId};
Expand Down Expand Up @@ -42,14 +40,11 @@ impl Work<Context, AnyWorkId, Error> for GvarWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Fe(FeWorkId::StaticMetadata)
| AnyWorkId::Fe(FeWorkId::GlyphOrder)
| AnyWorkId::Be(WorkId::GvarFragment(..))
)
}))
AccessBuilder::new()
.variant(FeWorkId::StaticMetadata)
.variant(FeWorkId::GlyphOrder)
.variant(WorkId::GvarFragment(GlyphName::NOTDEF))
.build()
}

/// Generate [gvar](https://learn.microsoft.com/en-us/typography/opentype/spec/gvar)
Expand Down
14 changes: 7 additions & 7 deletions fontbe/src/head.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Generates a [head](https://learn.microsoft.com/en-us/typography/opentype/spec/head) table.
use std::{collections::HashSet, env};
use std::env;

use chrono::{DateTime, TimeZone, Utc};
use fontdrasil::orchestration::{Access, Work};
use fontdrasil::orchestration::{Access, AccessBuilder, Work};
use fontir::orchestration::WorkId as FeWorkId;
use log::warn;
use write_fonts::{
Expand Down Expand Up @@ -96,11 +96,11 @@ impl Work<Context, AnyWorkId, Error> for HeadWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Set(HashSet::from([
FeWorkId::StaticMetadata.into(),
WorkId::Glyf.into(),
WorkId::LocaFormat.into(),
]))
AccessBuilder::new()
.variant(FeWorkId::StaticMetadata)
.variant(WorkId::Glyf)
.variant(WorkId::LocaFormat)
.build()
}

/// Generate [head](https://learn.microsoft.com/en-us/typography/opentype/spec/head)
Expand Down
15 changes: 6 additions & 9 deletions fontbe/src/hvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::any::type_name;
use std::collections::{BTreeSet, HashMap};
use std::sync::Arc;

use fontdrasil::orchestration::AccessBuilder;
use indexmap::IndexMap;

use fontdrasil::{
Expand Down Expand Up @@ -154,14 +154,11 @@ impl Work<Context, AnyWorkId, Error> for HvarWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Fe(FeWorkId::Glyph(..))
| AnyWorkId::Fe(FeWorkId::StaticMetadata)
| AnyWorkId::Fe(FeWorkId::GlyphOrder)
)
}))
AccessBuilder::new()
.variant(FeWorkId::StaticMetadata)
.variant(FeWorkId::GlyphOrder)
.variant(FeWorkId::Glyph(GlyphName::NOTDEF))
.build()
}

/// Generate [HVAR](https://learn.microsoft.com/en-us/typography/opentype/spec/HVAR)
Expand Down
14 changes: 7 additions & 7 deletions fontbe/src/kern.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Generates a [Kerning] datastructure to be fed to fea-rs
use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;

use fea_rs::{
compile::{PairPosBuilder, ValueRecord as ValueRecordBuilder},
GlyphSet,
};
use fontdrasil::orchestration::{Access, Work};
use fontdrasil::orchestration::{Access, AccessBuilder, Work};
use fontir::{ir::KernParticipant, orchestration::WorkId as FeWorkId};
use write_fonts::types::GlyphId;

Expand All @@ -29,11 +29,11 @@ impl Work<Context, AnyWorkId, Error> for KerningWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Set(HashSet::from([
FeWorkId::StaticMetadata.into(),
FeWorkId::Kerning.into(),
FeWorkId::GlyphOrder.into(),
]))
AccessBuilder::new()
.variant(FeWorkId::StaticMetadata)
.variant(FeWorkId::Kerning)
.variant(FeWorkId::GlyphOrder)
.build()
}

/// Generate kerning data structures.
Expand Down
15 changes: 6 additions & 9 deletions fontbe/src/marks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use fea_rs::compile::{MarkToBaseBuilder, MarkToMarkBuilder, PreviouslyAssignedClass};
use fontdrasil::{
orchestration::{Access, Work},
orchestration::{Access, AccessBuilder, Work},
types::GlyphName,
};

Expand Down Expand Up @@ -169,14 +169,11 @@ impl Work<Context, AnyWorkId, Error> for MarkWork {
}

fn read_access(&self) -> Access<AnyWorkId> {
Access::Custom(Arc::new(|id| {
matches!(
id,
AnyWorkId::Fe(FeWorkId::StaticMetadata)
| AnyWorkId::Fe(FeWorkId::GlyphOrder)
| AnyWorkId::Fe(FeWorkId::Anchor(..))
)
}))
AccessBuilder::new()
.variant(FeWorkId::StaticMetadata)
.variant(FeWorkId::GlyphOrder)
.variant(FeWorkId::Anchor(GlyphName::NOTDEF))
.build()
}

/// Generate mark data structures.
Expand Down
Loading

0 comments on commit 8991d75

Please sign in to comment.