From 486754a888d067c990d6a4351ccd41570f08c956 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 23 Sep 2019 23:48:08 +0330 Subject: [PATCH] [serialize] Extract iterable copy, copy_all --- src/hb-ot-cmap-table.hh | 6 +++--- src/hb-ot-layout-gpos-table.hh | 7 ++----- src/hb-ot-name-table.hh | 2 +- src/hb-ot-vorg-table.hh | 2 +- src/hb-serialize.hh | 6 ++++++ 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 9ebd8e417..7eddb2c86 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -941,9 +941,9 @@ struct CmapSubtableFormat14 if (unlikely (!c->extend_min (*this))) return; this->format = 14; - const CmapSubtableFormat14 *src_tbl = reinterpret_cast (src_base); - for (const VariationSelectorRecord& _ : src_tbl->record) - c->copy (_, unicodes, glyphs, glyph_map, src_base, this); + auto src_tbl = reinterpret_cast (src_base); + c->copy_all (hb_iter (src_tbl->record), + unicodes, glyphs, glyph_map, src_base, this); if (c->length () - table_initpos == CmapSubtableFormat14::min_size) c->revert (snap); diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index 024312d61..416d79c59 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -544,8 +544,7 @@ struct SinglePosFormat1 if (unlikely (!c->extend_min (*this))) return; if (unlikely (!c->check_assign (valueFormat, valFormat))) return; - for (const auto &_ : hb_second (*it)) - c->copy (_); + c->copy_all (hb_second (*it)); auto glyphs = + it @@ -632,9 +631,7 @@ struct SinglePosFormat2 if (unlikely (!c->check_assign (valueFormat, valFormat))) return; if (unlikely (!c->check_assign (valueCount, it.len ()))) return; - for (const auto iter : it) - for (const auto &_ : iter.second) - c->copy (_); + for (auto iter : it) c->copy_all (iter.second); auto glyphs = + it diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 84be04c8b..c0f9fbc1d 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -191,7 +191,7 @@ struct name const void *dst_string_pool = &(this + this->stringOffset); - for (const auto &_ : it) c->copy (_, src_string_pool, dst_string_pool); + c->copy_all (it, src_string_pool, dst_string_pool); if (unlikely (c->ran_out_of_room)) return_trace (false); diff --git a/src/hb-ot-vorg-table.hh b/src/hb-ot-vorg-table.hh index a4d6b0622..ff67983d1 100644 --- a/src/hb-ot-vorg-table.hh +++ b/src/hb-ot-vorg-table.hh @@ -84,7 +84,7 @@ struct VORG this->defaultVertOriginY = defaultVertOriginY; this->vertYOrigins.len = it.len (); - for (const auto _ : it) c->copy (_); + c->copy_all (it); } bool subset (hb_subset_context_t *c) const diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 4c674b1b1..ea6b3fce7 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -387,6 +387,12 @@ struct hb_serialize_context_t Type *copy (const Type *src, Ts&&... ds) { return copy (*src, hb_forward (ds)...); } + template + void copy_all (Iterator it, Ts&&... ds) + { for (decltype (*it) _ : it) copy (_, hb_forward (ds)...); } + template hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; }