diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 1e2f98f27..add21f115 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -884,19 +884,17 @@ struct NonDefaultUVS : SortedArray32Of { void collect_unicodes (hb_set_t *out) const { - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - out->add (arrayZ[i].unicodeValue); + for (const auto& a : as_array ()) + out->add (a.unicodeValue); } void collect_mapping (hb_set_t *unicodes, /* OUT */ hb_map_t *mapping /* OUT */) const { - unsigned count = len; - for (unsigned i = 0; i < count; i++) + for (const auto& a : as_array ()) { - hb_codepoint_t unicode = arrayZ[i].unicodeValue; - hb_codepoint_t glyphid = arrayZ[i].glyphID; + hb_codepoint_t unicode = a.unicodeValue; + hb_codepoint_t glyphid = a.glyphID; unicodes->add (unicode); mapping->set (unicode, glyphid); } @@ -1062,9 +1060,8 @@ struct CmapSubtableFormat14 void collect_variation_selectors (hb_set_t *out) const { - unsigned int count = record.len; - for (unsigned int i = 0; i < count; i++) - out->add (record.arrayZ[i].varSelector); + for (const auto& a : record.as_array ()) + out->add (a.varSelector); } void collect_variation_unicodes (hb_codepoint_t variation_selector, hb_set_t *out) const diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 00138cf57..7b230cd8f 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -557,7 +557,7 @@ struct IndexArray : Array16Of void add_indexes_to (hb_set_t* output /* OUT */) const { - output->add_array (arrayZ, len); + output->add_array (as_array ()); } }; @@ -1406,10 +1406,8 @@ struct CoverageFormat1 bool intersects (const hb_set_t *glyphs) const { /* TODO Speed up, using hb_set_next() and bsearch()? */ - unsigned int count = glyphArray.len; - const HBGlyphID *arr = glyphArray.arrayZ; - for (unsigned int i = 0; i < count; i++) - if (glyphs->has (arr[i])) + for (const auto& g : glyphArray.as_array ()) + if (glyphs->has (g)) return true; return false; } @@ -1426,7 +1424,7 @@ struct CoverageFormat1 template bool collect_coverage (set_t *glyphs) const - { return glyphs->add_sorted_array (glyphArray.arrayZ, glyphArray.len); } + { return glyphs->add_sorted_array (glyphArray.as_array ()); } public: /* Older compilers need this to be public. */ @@ -1522,20 +1520,16 @@ struct CoverageFormat2 { /* TODO Speed up, using hb_set_next() and bsearch()? */ /* TODO(iter) Rewrite as dagger. */ - unsigned count = rangeRecord.len; - const RangeRecord *arr = rangeRecord.arrayZ; - for (unsigned i = 0; i < count; i++) - if (arr[i].intersects (glyphs)) + for (const auto& range : rangeRecord.as_array ()) + if (range.intersects (glyphs)) return true; return false; } bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { /* TODO(iter) Rewrite as dagger. */ - unsigned count = rangeRecord.len; - const RangeRecord *arr = rangeRecord.arrayZ; - for (unsigned i = 0; i < count; i++) { - const RangeRecord &range = arr[i]; + for (const auto& range : rangeRecord.as_array ()) + { if (range.value <= index && index < (unsigned int) range.value + (range.last - range.first) && range.intersects (glyphs)) @@ -1548,10 +1542,8 @@ struct CoverageFormat2 void intersected_coverage_glyphs (const hb_set_t *glyphs, hb_set_t *intersect_glyphs) const { - unsigned count = rangeRecord.len; - for (unsigned i = 0; i < count; i++) + for (const auto& range : rangeRecord.as_array ()) { - const RangeRecord &range = rangeRecord[i]; if (!range.intersects (glyphs)) continue; for (hb_codepoint_t g = range.first; g <= range.last; g++) if (glyphs->has (g)) intersect_glyphs->add (g); diff --git a/src/hb-set.hh b/src/hb-set.hh index ae8b5eb10..6840dde58 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -337,6 +337,8 @@ struct hb_set_t while (count && (g = *array, start <= g && g < end)); } } + template + void add_array (const hb_array_t& arr) { add_array (&arr, arr.len ()); } /* Might return false if array looks unsorted. * Used for faster rejection of corrupt data. */ @@ -368,6 +370,8 @@ struct hb_set_t } return true; } + template + bool add_sorted_array (const hb_sorted_array_t& arr) { return add_sorted_array (&arr, arr.len ()); } void del (hb_codepoint_t g) {