Skip to content

Commit 9afb24e

Browse files
authored
Contextual tuning (#137)
* [contextual] Micro-micro-optimize Just don't rely on the compiler to optimize. * [contextual] Tune fast path
1 parent b5af506 commit 9afb24e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/hb/ot/contextual.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ fn match_class_cached2<'a>(
328328

329329
impl Apply for ChainedSequenceContextFormat2<'_> {
330330
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
331+
let glyph = ctx.buffer.cur(0).as_gid16()?;
332+
self.coverage().ok()?.get(glyph)?;
331333
let backtrack_classes = self.backtrack_class_def().ok();
332334
let input_classes = self.input_class_def().ok();
333335
let lookahead_classes = self.lookahead_class_def().ok();
334-
let glyph = ctx.buffer.cur(0).as_gid16()?;
335-
self.coverage().ok()?.get(glyph)?;
336336
let index = input_classes.as_ref()?.get(glyph) as usize;
337337
let set = self.chained_class_seq_rule_sets().get(index)?.ok()?;
338338
apply_chain_context_rules(
@@ -350,11 +350,11 @@ impl Apply for ChainedSequenceContextFormat2<'_> {
350350
ctx: &mut hb_ot_apply_context_t,
351351
_: &SubtableExternalCache,
352352
) -> Option<()> {
353+
let glyph = ctx.buffer.cur(0).as_gid16()?;
354+
self.coverage().ok()?.get(glyph)?;
353355
let backtrack_classes = self.backtrack_class_def().ok();
354356
let input_classes = self.input_class_def().ok();
355357
let lookahead_classes = self.lookahead_class_def().ok();
356-
let glyph = ctx.buffer.cur(0).as_gid16()?;
357-
self.coverage().ok()?.get(glyph)?;
358358
let index =
359359
get_class_cached2(&input_classes, &mut ctx.buffer.info[ctx.buffer.idx]) as usize;
360360
let set = self.chained_class_seq_rule_sets().get(index)?.ok()?;
@@ -568,7 +568,11 @@ fn apply_context_rules<'a, 'b, R: ContextRule<'a>>(
568568
rules: &'b ArrayOfOffsets<'a, R, Offset16>,
569569
match_func: impl Fn(&mut hb_glyph_info_t, u16) -> bool,
570570
) -> Option<()> {
571-
if rules.len() <= 4 {
571+
// TODO: In HarfBuzz, the following condition makes NotoNastaliqUrdu
572+
// faster. But our lookup code is slower, so NOT using this condition
573+
// makes us faster. Reconsider when lookup code is faster.
574+
//if rules.len() <= 4 {
575+
if false {
572576
for rule in rules.iter().filter_map(|r| r.ok()) {
573577
if rule.apply(ctx, &match_func).is_some() {
574578
return Some(());
@@ -791,7 +795,12 @@ fn apply_chain_context_rules<
791795
// skip this fast path, as we don't distinguish between input & lookahead
792796
// matching in the fast path.
793797
// https://github.com/harfbuzz/harfbuzz/issues/4813
794-
if rules.len() <= 4 || !ctx.auto_zwnj || !ctx.auto_zwj {
798+
//
799+
// TODO: In HarfBuzz, the following condition makes NotoNastaliqUrdu
800+
// faster. But our lookup code is slower, so NOT using this condition
801+
// makes us faster. Reconsider when lookup code is faster.
802+
//if rules.len() <= 4 || !ctx.auto_zwnj || !ctx.auto_zwj {
803+
if !ctx.auto_zwnj || !ctx.auto_zwj {
795804
for rule in rules.iter().filter_map(|r| r.ok()) {
796805
if rule.apply_chain(ctx, &match_funcs).is_some() {
797806
return Some(());

0 commit comments

Comments
 (0)