From 05c17787c4fc5283925920b546952ccca0ba4a00 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 16:55:08 -0600 Subject: [PATCH 1/9] [buffer] Rewind cursor in clear_output() --- src/hb-buffer.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 7aa37eaf0..7ca988dbc 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -297,6 +297,7 @@ hb_buffer_t::clear_output () have_output = true; have_positions = false; + idx = 0; out_len = 0; out_info = info; } From a623446a34a4a388f86afc97ed9c5a74792d5420 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 16:55:54 -0600 Subject: [PATCH 2/9] [shape] Remove stray clear_output() call in hb_shape() --- src/hb-ot-shape.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index b70dece91..246936db3 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -1158,8 +1158,6 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) _hb_buffer_allocate_unicode_vars (c->buffer); - c->buffer->clear_output (); - hb_ot_shape_initialize_masks (c); hb_set_unicode_props (c->buffer); hb_insert_dotted_circle (c->buffer, c->font); From 431f164003d1d92b657b3facf984c8bbe342418b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 16:57:25 -0600 Subject: [PATCH 3/9] [layout] Don't call clear_output() before pause-func --- src/hb-ot-layout.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 257cc916e..379d92e6a 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1942,10 +1942,7 @@ inline void hb_ot_map_t::apply (const Proxy &proxy, } if (stage->pause_func) - { - buffer->clear_output (); stage->pause_func (plan, font, buffer); - } } } From 62b441e6ff798f1d551d290a2a4970482254dbe2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 16:59:34 -0600 Subject: [PATCH 4/9] [layout] Use Proxy::inplace instead of table index check Equivalent. --- src/hb-ot-layout.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 379d92e6a..340c95f7f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1886,8 +1886,9 @@ apply_string (OT::hb_ot_apply_context_t *c, if (likely (!lookup.is_reverse ())) { /* in/out forward substitution/positioning */ - if (Proxy::table_index == 0u) + if (!Proxy::inplace) buffer->clear_output (); + buffer->idx = 0; bool ret; From a7f4c985a8080797482c971a7b6275636fe5be62 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 17:00:46 -0600 Subject: [PATCH 5/9] [ot-layout] Always swap_buffers() even if no substitutions happened --- src/hb-ot-layout.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 340c95f7f..85795556f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1890,16 +1890,12 @@ apply_string (OT::hb_ot_apply_context_t *c, buffer->clear_output (); buffer->idx = 0; + apply_forward (c, accel); - bool ret; - ret = apply_forward (c, accel); - if (ret) - { - if (!Proxy::inplace) - buffer->swap_buffers (); - else - assert (!buffer->has_separate_output ()); - } + if (!Proxy::inplace) + buffer->swap_buffers (); + else + assert (!buffer->has_separate_output ()); } else { From 10a9960f0af9d6fb93ff3d234b2a989f9bc00b21 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 17:09:03 -0600 Subject: [PATCH 6/9] [buffer] Restructure swap_buffers() Is more of a "commit" operation now. Will rename when ready. --- src/hb-buffer.cc | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 7ca988dbc..583137a58 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -317,29 +317,23 @@ hb_buffer_t::clear_positions () void hb_buffer_t::swap_buffers () { - if (unlikely (!successful)) return; + assert (have_output); assert (idx <= len); - if (unlikely (!next_glyphs (len - idx))) return; - assert (have_output); - have_output = false; + if (unlikely (!successful || !next_glyphs (len - idx))) + goto reset; if (out_info != info) { - hb_glyph_info_t *tmp; - tmp = info; + pos = (hb_glyph_position_t *) info; info = out_info; - out_info = tmp; - - pos = (hb_glyph_position_t *) out_info; } - - unsigned int tmp; - tmp = len; len = out_len; - out_len = tmp; +reset: + have_output = false; + out_len = 0; idx = 0; } From 3807061d634b60bd6235d6e1d8c47a034377f924 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 17:02:03 -0600 Subject: [PATCH 7/9] [ot-layout] Don't remove_output() before reverse substitution No need anymore, because of new swap_buffers() semantics. Just assert instead. --- src/hb-buffer.cc | 10 ---------- src/hb-buffer.hh | 1 - src/hb-ot-layout.cc | 4 +--- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 583137a58..82aeaae0f 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -281,16 +281,6 @@ hb_buffer_t::add_info (const hb_glyph_info_t &glyph_info) } -void -hb_buffer_t::remove_output () -{ - have_output = false; - have_positions = false; - - out_len = 0; - out_info = info; -} - void hb_buffer_t::clear_output () { diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 33d6e6c66..67429df23 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -209,7 +209,6 @@ struct hb_buffer_t HB_INTERNAL void guess_segment_properties (); HB_INTERNAL void swap_buffers (); - HB_INTERNAL void remove_output (); HB_INTERNAL void clear_output (); HB_INTERNAL void clear_positions (); diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 85795556f..cb428fba8 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1900,10 +1900,8 @@ apply_string (OT::hb_ot_apply_context_t *c, else { /* in-place backward substitution/positioning */ - if (Proxy::table_index == 0u) - buffer->remove_output (); + assert (!buffer->have_output); buffer->idx = buffer->len - 1; - apply_backward (c, accel); } } From 3e266e5f64b6d078d64fe0f3783f774d7e29472d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 17:30:26 -0600 Subject: [PATCH 8/9] [buffer] Update comments --- src/hb-buffer.cc | 9 +++++---- src/hb-buffer.hh | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 82aeaae0f..c147dfcce 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -96,14 +96,15 @@ hb_segment_properties_hash (const hb_segment_properties_t *p) * As an optimization, both info and out_info may point to the * same piece of memory, which is owned by info. This remains the * case as long as out_len doesn't exceed i at any time. - * In that case, swap_buffers() is no-op and the glyph operations operate - * mostly in-place. + * In that case, swap_buffers() is mostly no-op and the glyph operations + * operate mostly in-place. * * As soon as out_info gets longer than info, out_info is moved over - * to an alternate buffer (which we reuse the pos buffer for!), and its + * to an alternate buffer (which we reuse the pos buffer for), and its * current contents (out_len entries) are copied to the new place. + * * This should all remain transparent to the user. swap_buffers() then - * switches info and out_info. + * switches info over to out_info and does housekeeping. */ diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 67429df23..1d47a71a7 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -107,7 +107,7 @@ struct hb_buffer_t unsigned int idx; /* Cursor into ->info and ->pos arrays */ unsigned int len; /* Length of ->info and ->pos arrays */ - unsigned int out_len; /* Length of ->out array if have_output */ + unsigned int out_len; /* Length of ->out_info array if have_output */ unsigned int allocated; /* Length of allocated arrays */ hb_glyph_info_t *info; From 95b04f7409e5af6dec97feb4ed18ba0bfae2cd88 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 12 Jul 2021 17:35:45 -0600 Subject: [PATCH 9/9] [buffer] Remove unnecessary have_separate_output() --- src/hb-buffer.hh | 5 +---- src/hb-ot-layout.cc | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 1d47a71a7..8635ebd35 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -189,13 +189,10 @@ struct hb_buffer_t hb_glyph_info_t &prev () { return out_info[out_len ? out_len - 1 : 0]; } hb_glyph_info_t prev () const { return out_info[out_len ? out_len - 1 : 0]; } - HB_NODISCARD bool has_separate_output () const { return info != out_info; } - - HB_INTERNAL void reset (); HB_INTERNAL void clear (); - unsigned int backtrack_len () const { return have_output? out_len : idx; } + unsigned int backtrack_len () const { return have_output ? out_len : idx; } unsigned int lookahead_len () const { return len - idx; } unsigned int next_serial () { return serial++; } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index cb428fba8..0454af206 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1894,8 +1894,6 @@ apply_string (OT::hb_ot_apply_context_t *c, if (!Proxy::inplace) buffer->swap_buffers (); - else - assert (!buffer->has_separate_output ()); } else {