From 68c372ed2eac76a6d347811293fe2ba2fd6a1eed Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 13 Nov 2013 14:44:01 -0500 Subject: [PATCH] More scratch-buffer cleanup --- src/hb-buffer-private.hh | 3 ++- src/hb-buffer.cc | 10 +++++----- src/hb-coretext.cc | 5 ++--- src/hb-graphite2.cc | 2 +- src/hb-uniscribe.cc | 30 ++++++++++++++---------------- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 4647b9b4c..478bad0ef 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -186,7 +186,8 @@ struct hb_buffer_t { HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); HB_INTERNAL bool shift_forward (unsigned int count); - HB_INTERNAL int *get_scratch_buffer (unsigned int *int_size); + typedef int scratch_buffer_t; + HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size); inline void clear_context (unsigned int side) { context_len[side] = 0; } }; diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index c5a74c30f..df2ad7360 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -152,8 +152,8 @@ hb_buffer_t::shift_forward (unsigned int count) return true; } -int * -hb_buffer_t::get_scratch_buffer (unsigned int *int_size) +hb_buffer_t::scratch_buffer_t * +hb_buffer_t::get_scratch_buffer (unsigned int *size) { have_output = false; have_positions = false; @@ -161,9 +161,9 @@ hb_buffer_t::get_scratch_buffer (unsigned int *int_size) out_len = 0; out_info = info; - ASSERT_STATIC (sizeof (pos[0]) % sizeof (int) == 0); - *int_size = allocated * (sizeof (pos[0]) / sizeof (int)); - return (int *) pos; + ASSERT_STATIC (sizeof (pos[0]) % sizeof (scratch_buffer_t) == 0); + *size = allocated * sizeof (pos[0]) / sizeof (scratch_buffer_t); + return (scratch_buffer_t *) pos; } diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index eafa68ec1..ba8013604 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -553,7 +553,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, } HB_STMT_END; unsigned int scratch_size; - int *scratch = buffer->get_scratch_buffer (&scratch_size); + hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size); #define ALLOCATE_ARRAY(Type, name, len) \ Type *name = (Type *) scratch; \ @@ -657,8 +657,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, buffer->ensure (buffer->len + num_glyphs); - unsigned int scratch_size; - int *scratch = buffer->get_scratch_buffer (&scratch_size); + scratch = buffer->get_scratch_buffer (&scratch_size); /* Testing indicates that CTRunGetGlyphsPtr, etc (almost?) always * succeed, and so copying data to our own buffer will be rare. */ diff --git a/src/hb-graphite2.cc b/src/hb-graphite2.cc index d1cd1dc52..60d68d6b5 100644 --- a/src/hb-graphite2.cc +++ b/src/hb-graphite2.cc @@ -243,7 +243,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan, float curradvx = 0., curradvy = 0.; unsigned int scratch_size; - int *scratch = buffer->get_scratch_buffer (&scratch_size); + hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size); uint32_t *chars = (uint32_t *) scratch; diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 4a93db840..fcb1aa65d 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -729,13 +729,21 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, retry: unsigned int scratch_size; - int *scratch = buffer->get_scratch_buffer (&scratch_size); + hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size); - /* Allocate char buffers; they all fit */ +#define ALLOCATE_ARRAY(Type, name, len) \ + Type *name = (Type *) scratch; \ + { \ + unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \ + assert (_consumed <= scratch_size); \ + scratch += _consumed; \ + scratch_size -= _consumed; \ + } #define utf16_index() var1.u32 - WCHAR *pchars = (WCHAR *) scratch; + ALLOCATE_ARRAY (WCHAR, pchars, buffer->len * 2); + unsigned int chars_len = 0; for (unsigned int i = 0; i < buffer->len; i++) { @@ -751,16 +759,6 @@ retry: } } -#define ALLOCATE_ARRAY(Type, name, len) \ - Type *name = (Type *) scratch; \ - { \ - unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \ - assert (_consumed <= scratch_size); \ - scratch += _consumed; \ - scratch_size -= _consumed; \ - } - - ALLOCATE_ARRAY (WCHAR, wchars, chars_len); ALLOCATE_ARRAY (WORD, log_clusters, chars_len); ALLOCATE_ARRAY (SCRIPT_CHARPROP, char_props, chars_len); @@ -817,7 +815,7 @@ retry: bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1; bidi_state.fOverrideDirection = 1; - hr = funcs->ScriptItemizeOpenType (wchars, + hr = funcs->ScriptItemizeOpenType (pchars, chars_len, MAX_ITEMS, &bidi_control, @@ -892,7 +890,7 @@ retry: range_char_counts.array, range_properties.array, range_properties.len, - wchars + chars_offset, + pchars + chars_offset, item_chars_len, glyphs_size - glyphs_offset, /* out */ @@ -934,7 +932,7 @@ retry: range_char_counts.array, range_properties.array, range_properties.len, - wchars + chars_offset, + pchars + chars_offset, log_clusters + chars_offset, char_props + chars_offset, item_chars_len,