From b154b1e4c3564bcef14f6efe9062e543808ed659 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 4 Aug 2022 01:37:21 +0000 Subject: [PATCH] [repacker] pull out PairPosFormat1,2::do_split() into a common helper method. --- src/Makefile.sources | 1 + src/graph/pairpos-graph.hh | 113 +++++++++++++++---------------------- src/graph/split-helpers.hh | 68 ++++++++++++++++++++++ src/meson.build | 1 + 4 files changed, 115 insertions(+), 68 deletions(-) create mode 100644 src/graph/split-helpers.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index 14c6ed346..0a6b845ee 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -355,6 +355,7 @@ HB_SUBSET_sources = \ graph/coverage-graph.hh \ graph/classdef-graph.hh \ graph/pairpos-graph.hh \ + graph/split-helpers.hh \ graph/serialize.hh \ $(NULL) diff --git a/src/graph/pairpos-graph.hh b/src/graph/pairpos-graph.hh index aa504e0e1..6b0e4e075 100644 --- a/src/graph/pairpos-graph.hh +++ b/src/graph/pairpos-graph.hh @@ -27,6 +27,7 @@ #ifndef GRAPH_PAIRPOS_GRAPH_HH #define GRAPH_PAIRPOS_GRAPH_HH +#include "split-helpers.hh" #include "coverage-graph.hh" #include "classdef-graph.hh" #include "../OT/Layout/GPOS/PairPos.hh" @@ -75,45 +76,37 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 (split_context, split_points); } private: - // Split this PairPos into two or more PairPos's. split_points defines - // the indices (first index to include in the new table) to split at. - // Returns the object id's of the newly created PairPos subtables. - hb_vector_t do_split (gsubgpos_graph_context_t& c, - unsigned this_index, - const hb_vector_t split_points) - { - hb_vector_t new_objects; - if (!split_points) - return new_objects; + struct split_context_t { + gsubgpos_graph_context_t& c; + PairPosFormat1* thiz; + unsigned this_index; - for (unsigned i = 0; i < split_points.length; i++) + unsigned original_count () { - unsigned start = split_points[i]; - unsigned end = (i < split_points.length - 1) ? split_points[i + 1] : pairSet.len; - unsigned id = clone_range (c, this_index, start, end); - - if (id == (unsigned) -1) - { - new_objects.reset (); - new_objects.allocated = -1; // mark error - return new_objects; - } - new_objects.push (id); + return thiz->pairSet.len; } - if (!shrink (c, this_index, split_points[0])) + unsigned clone_range (unsigned start, unsigned end) { - new_objects.reset (); - new_objects.allocated = -1; // mark error + return thiz->clone_range (this->c, this->this_index, start, end); } - return new_objects; - } + bool shrink (unsigned count) + { + return thiz->shrink (this->c, this->this_index, count); + } + }; bool shrink (gsubgpos_graph_context_t& c, unsigned this_index, @@ -267,8 +260,9 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 (split_context, split_points); } private: - struct split_context + struct split_context_t { gsubgpos_graph_context_t& c; + PairPosFormat2* thiz; unsigned this_index; unsigned class1_record_size; unsigned value_record_len; @@ -295,6 +290,21 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4& device_tables; const hb_vector_t& format1_device_table_indices; const hb_vector_t& format2_device_table_indices; + + unsigned original_count () + { + return thiz->class1Count; + } + + unsigned clone_range (unsigned start, unsigned end) + { + return thiz->clone_range (*this, start, end); + } + + bool shrink (unsigned count) + { + return thiz->shrink (*this, count); + } }; size_t get_class1_record_size () const @@ -304,40 +314,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 do_split (split_context& split_context, - const hb_vector_t& split_points) - { - // TODO(garretrieger): refactor into a common method shared between subtables. - // template on context which could provide the clone and shrink methods. - hb_vector_t new_objects; - if (!split_points) - return new_objects; - - for (unsigned i = 0; i < split_points.length; i++) - { - unsigned start = split_points[i]; - unsigned end = (i < split_points.length - 1) ? split_points[i + 1] : class1Count; - unsigned id = clone_range (split_context, start, end); - - if (id == (unsigned) -1) - { - new_objects.reset (); - new_objects.allocated = -1; // mark error - return new_objects; - } - new_objects.push (id); - } - - if (!shrink (split_context, split_points[0])) - { - new_objects.reset (); - new_objects.allocated = -1; // mark error - } - - return new_objects; - } - - unsigned clone_range (split_context& split_context, + unsigned clone_range (split_context_t& split_context, unsigned start, unsigned end) const { DEBUG_MSG (SUBSET_REPACK, nullptr, @@ -396,7 +373,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4& device_table_indices, unsigned old_value_record_index, @@ -462,7 +439,7 @@ struct PairPosFormat2 : public OT::Layout::GPOS_impl::PairPosFormat2_4 +hb_vector_t actuate_subtable_split (Context& split_context, + const hb_vector_t& split_points) +{ + hb_vector_t new_objects; + if (!split_points) + return new_objects; + + for (unsigned i = 0; i < split_points.length; i++) + { + unsigned start = split_points[i]; + unsigned end = (i < split_points.length - 1) + ? split_points[i + 1] + : split_context.original_count (); + unsigned id = split_context.clone_range (start, end); + + if (id == (unsigned) -1) + { + new_objects.reset (); + new_objects.allocated = -1; // mark error + return new_objects; + } + new_objects.push (id); + } + + if (!split_context.shrink (split_points[0])) + { + new_objects.reset (); + new_objects.allocated = -1; // mark error + } + + return new_objects; +} + +} + +#endif // GRAPH_SPLIT_HELPERS_HH diff --git a/src/meson.build b/src/meson.build index 2118eb57c..5e0c172c6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -351,6 +351,7 @@ hb_subset_sources = files( 'graph/pairpos-graph.hh', 'graph/coverage-graph.hh', 'graph/classdef-graph.hh', + 'graph/split-helpers.hh', 'hb-subset.cc', 'hb-subset.hh', )