From dfa9d7acdc320005749bb21b4c4711224a87d511 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 11 Feb 2021 11:08:52 -0700 Subject: [PATCH] [minor] Use serializer->propagate_error() to simplify code --- src/hb-ot-color-cbdt-table.hh | 8 ++++---- src/hb-ot-layout-gsubgpos.hh | 18 ++++++++---------- src/hb-serialize.hh | 9 +++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index aaa1c37c6..e285acec3 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -455,8 +455,8 @@ struct IndexSubtableRecord unsigned int old_cbdt_prime_length = bitmap_size_context->cbdt_prime->length; // Set to invalid state to indicate filling glyphs is not yet started. - if (unlikely (!records->resize (records->length + 1))) - return_trace (c->serializer->check_success (false)); + if (unlikely (!c->serializer->check_success (records->resize (records->length + 1)))) + return_trace (false); (*records)[records->length - 1].firstGlyphIndex = 1; (*records)[records->length - 1].lastGlyphIndex = 0; @@ -567,8 +567,8 @@ struct IndexSubtableArray hb_vector_t> lookup; build_lookup (c, bitmap_size_context, &lookup); - if (unlikely (lookup.in_error ())) - return c->serializer->check_success (false); + if (unlikely (!c->serializer->propagate_error (lookup))) + return false; bitmap_size_context->size = 0; bitmap_size_context->num_tables = 0; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 82ef69412..fbfb07671 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2838,19 +2838,17 @@ struct ChainContextFormat2 out->coverage.serialize_subset (c, coverage, this); hb_map_t backtrack_klass_map; - out->backtrackClassDef.serialize_subset (c, backtrackClassDef, this, &backtrack_klass_map); - if (unlikely (!c->serializer->check_success (!backtrack_klass_map.in_error ()))) - return_trace (false); - - // subset inputClassDef based on glyphs survived in Coverage subsetting hb_map_t input_klass_map; - out->inputClassDef.serialize_subset (c, inputClassDef, this, &input_klass_map); - if (unlikely (!c->serializer->check_success (!input_klass_map.in_error ()))) - return_trace (false); - hb_map_t lookahead_klass_map; + + out->backtrackClassDef.serialize_subset (c, backtrackClassDef, this, &backtrack_klass_map); + // TODO: subset inputClassDef based on glyphs survived in Coverage subsetting + out->inputClassDef.serialize_subset (c, inputClassDef, this, &input_klass_map); out->lookaheadClassDef.serialize_subset (c, lookaheadClassDef, this, &lookahead_klass_map); - if (unlikely (!c->serializer->check_success (!lookahead_klass_map.in_error ()))) + + if (unlikely (!c->serializer->propagate_error (backtrack_klass_map, + input_klass_map, + lookahead_klass_map))) return_trace (false); int non_zero_index = -1, index = 0; diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 4566153a5..7238fb0d8 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -256,10 +256,11 @@ struct hb_serialize_context_t packed.push (obj); - if (unlikely (packed.in_error ())) { - // obj wasn't successfully added to packed, so clean it up otherwise it's - // links will be leaked. - propagate_error (packed); + if (unlikely (!propagate_error (packed))) + { + /* Obj wasn't successfully added to packed, so clean it up otherwise its + * links will be leaked. When we use constructor/destructors properly, we + * can remove these. */ obj->fini (); return 0; }