From da9edce84c340d5495861aadc66d9d2797fafb7b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 21 Mar 2022 18:51:01 -0600 Subject: [PATCH] [buffer] Add sync_so_far() This removes separate out-buffer, at the cost of possibly changing idx. --- src/hb-buffer.cc | 28 +++++++++++++++++++++++++++- src/hb-buffer.hh | 3 ++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index fddda2330..e09dee77f 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -387,9 +387,11 @@ hb_buffer_t::clear_positions () hb_memset (pos, 0, sizeof (pos[0]) * len); } -void +bool hb_buffer_t::sync () { + bool ret = false; + assert (have_output); assert (idx <= len); @@ -403,12 +405,36 @@ hb_buffer_t::sync () info = out_info; } len = out_len; + ret = true; reset: have_output = false; out_len = 0; out_info = info; idx = 0; + + return ret; +} + +void +hb_buffer_t::sync_so_far () +{ + bool had_output = have_output; + unsigned out_i = out_len; + unsigned i = idx; + + if (sync ()) + idx = out_i; + else + idx = i; + + if (had_output) + { + have_output = true; + out_len = idx; + } + + assert (idx <= len); } bool diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 6ca78f28d..5ad273ce8 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -288,7 +288,8 @@ struct hb_buffer_t HB_INTERNAL void guess_segment_properties (); - HB_INTERNAL void sync (); + HB_INTERNAL bool sync (); + HB_INTERNAL void sync_so_far (); HB_INTERNAL void clear_output (); HB_INTERNAL void clear_positions ();