From 65aeabd62275b37c6bb6715f3341e45625f4ba6e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 23 May 2018 16:15:28 -0700 Subject: [PATCH] Add hb_vector_t::push(const Type &v) Makes for cleaner code. --- src/hb-coretext.cc | 3 +-- src/hb-ot-post-table.hh | 3 +-- src/hb-private.hh | 18 +++++++++++------- src/hb-subset-plan.cc | 12 +++++------- src/hb-uniscribe.cc | 8 ++------ 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 3924c8e..84cc22f 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -770,10 +770,9 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, } if (event->start) { - active_feature_t *feature = active_features.push (); + active_feature_t *feature = active_features.push (event->feature); if (unlikely (!feature)) goto fail_features; - *feature = event->feature; } else { active_feature_t *feature = active_features.find (&event->feature); if (feature) diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index bec508c..9a1edea 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -126,10 +126,9 @@ struct post const uint8_t *end = (uint8_t *) table + table_length; for (const uint8_t *data = pool; data < end && data + *data <= end; data += 1 + *data) { - uint32_t *offset = index_to_offset.push (); + uint32_t *offset = index_to_offset.push (data - pool); if (unlikely (!offset)) break; - *offset = data - pool; } } inline void fini (void) diff --git a/src/hb-private.hh b/src/hb-private.hh index 183f2a4..d3381eb 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -551,9 +551,17 @@ struct hb_vector_t return &arrayZ[len - 1]; } + inline Type *push (const Type& v) + { + if (unlikely (!resize (len + 1))) + return nullptr; + + arrayZ[len - 1] = v; + return &arrayZ[len - 1]; + } /* Allocate for size but don't adjust len. */ - inline bool alloc(unsigned int size) + inline bool alloc (unsigned int size) { if (likely (size <= allocated)) return true; @@ -738,9 +746,7 @@ struct hb_lockable_set_t l.unlock (); } } else { - item = items.push (); - if (likely (item)) - *item = v; + item = items.push (v); l.unlock (); } return item; @@ -779,9 +785,7 @@ struct hb_lockable_set_t l.lock (); item_t *item = items.find (v); if (!item) { - item = items.push (); - if (likely (item)) - *item = v; + item = items.push (v); } l.unlock (); return item; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index d70215b..3e53e84 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -91,10 +91,8 @@ _populate_codepoints (hb_set_t *input_codepoints, { plan_codepoints.alloc (hb_set_get_population (input_codepoints)); hb_codepoint_t cp = -1; - while (hb_set_next (input_codepoints, &cp)) { - hb_codepoint_t *wr = plan_codepoints.push(); - *wr = cp; - } + while (hb_set_next (input_codepoints, &cp)) + plan_codepoints.push(cp); plan_codepoints.qsort (_hb_codepoint_t_cmp); } @@ -139,9 +137,9 @@ _populate_gids_to_retain (hb_face_t *face, if (!cmap.get_nominal_glyph (codepoints[i], &gid)) { gid = -1; - *(bad_indices.push ()) = i; + bad_indices.push (i); } - *(old_gids.push ()) = gid; + old_gids.push (gid); } /* Generally there shouldn't be any */ @@ -166,7 +164,7 @@ _populate_gids_to_retain (hb_face_t *face, old_gids_sorted.alloc (hb_set_get_population (all_gids_to_retain)); hb_codepoint_t gid = HB_SET_VALUE_INVALID; while (hb_set_next (all_gids_to_retain, &gid)) - *(old_gids_sorted.push ()) = gid; + old_gids_sorted.push (gid); hb_set_destroy (all_gids_to_retain); glyf.fini (); diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 3cd419e..3b52ad3 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -696,10 +696,8 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, { if (!j || active_features[j].rec.tagFeature != feature_records[feature_records.len - 1].tagFeature) { - OPENTYPE_FEATURE_RECORD *feature = feature_records.push (); - if (unlikely (!feature)) + if (unlikely (!feature_records.push (active_features[j].rec))) goto fail_features; - *feature = active_features[j].rec; } else { @@ -719,10 +717,8 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, } if (event->start) { - active_feature_t *feature = active_features.push (); - if (unlikely (!feature)) + if (unlikely (!active_features.push (event->feature))) goto fail_features; - *feature = event->feature; } else { active_feature_t *feature = active_features.find (&event->feature); if (feature) -- 2.7.4