From 955aa56b11e4fa14bc6d5b1b56cb810e28fab6cd Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 25 Oct 2018 16:50:38 -0700 Subject: [PATCH] [vector] Make it act more like pointer Add pointer cast operator and plus operator. --- src/hb-coretext.cc | 2 +- src/hb-machinery.hh | 2 +- src/hb-ot-cmap-table.hh | 2 +- src/hb-set.hh | 8 ++++---- src/hb-subset.cc | 2 +- src/hb-uniscribe.cc | 12 ++++++------ src/hb-vector.hh | 6 ++++++ 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 9f7745db..54e3f9cc 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -586,7 +586,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan, } else { active_feature_t *feature = active_features.find (&event->feature); if (feature) - active_features.remove (feature - active_features.arrayZ()); + active_features.remove (feature - active_features); } } } diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 19245e89..35cbc155 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -612,7 +612,7 @@ struct Supplier } inline Supplier (const hb_vector_t *v) { - head = v->arrayZ(); + head = *v; len = v->len; stride = sizeof (Type); } diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 9978d1b0..d5b4fde3 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -495,7 +495,7 @@ struct CmapSubtableLongSegmented { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - Supplier supplier (group_data.arrayZ(), group_data.len); + Supplier supplier (group_data, group_data.len); if (unlikely (!groups.serialize (c, supplier, group_data.len))) return_trace (false); return true; } diff --git a/src/hb-set.hh b/src/hb-set.hh index 4a7e74b6..2071196b 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -368,8 +368,8 @@ struct hb_set_t if (!resize (count)) return; population = other->population; - memcpy (pages.arrayZ(), other->pages.arrayZ(), count * sizeof (pages[0])); - memcpy (page_map.arrayZ(), other->page_map.arrayZ(), count * sizeof (page_map[0])); + memcpy (pages, other->pages, count * sizeof (pages[0])); + memcpy (page_map, other->page_map, count * sizeof (page_map[0])); } inline bool is_equal (const hb_set_t *other) const @@ -669,8 +669,8 @@ struct hb_set_t return nullptr; pages[map.index].init0 (); - memmove (page_map.arrayZ() + i + 1, - page_map.arrayZ() + i, + memmove (page_map + i + 1, + page_map + i, (page_map.len - 1 - i) * sizeof (page_map[0])); page_map[i] = map; } diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 9f14b89b..294fd846 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -77,7 +77,7 @@ _subset2 (hb_subset_plan_t *plan) return false; } retry: - hb_serialize_context_t serializer (buf.arrayZ(), buf_size); + hb_serialize_context_t serializer (buf, buf_size); hb_subset_context_t c (plan, &serializer); result = table->subset (&c); if (serializer.ran_out_of_room) diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 44a67ae4..c3949c98 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -717,7 +717,7 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, { active_feature_t *feature = active_features.find (&event->feature); if (feature) - active_features.remove (feature - active_features.arrayZ()); + active_features.remove (feature - active_features); } } @@ -728,7 +728,7 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan, for (unsigned int i = 0; i < range_records.len; i++) { range_record_t *range = &range_records[i]; - range->props.potfRecords = feature_records.arrayZ() + reinterpret_cast (range->props.potfRecords); + range->props.potfRecords = feature_records + reinterpret_cast (range->props.potfRecords); } } @@ -902,8 +902,8 @@ retry: &items[i].a, script_tags[i], language_tag, - range_char_counts.arrayZ(), - range_properties.arrayZ(), + range_char_counts, + range_properties, range_properties.len, pchars + chars_offset, item_chars_len, @@ -943,8 +943,8 @@ retry: &items[i].a, script_tags[i], language_tag, - range_char_counts.arrayZ(), - range_properties.arrayZ(), + range_char_counts, + range_properties, range_properties.len, pchars + chars_offset, log_clusters + chars_offset, diff --git a/src/hb-vector.hh b/src/hb-vector.hh index eed4507f..8995ae10 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -66,6 +66,12 @@ struct hb_vector_t return arrayZ()[i]; } + template inline operator T * (void) { return arrayZ(); } + template inline operator const T * (void) const { return arrayZ(); } + + inline Type * operator + (unsigned int i) { return arrayZ() + i; } + inline const Type * operator + (unsigned int i) const { return arrayZ() + i; } + inline Type *push (void) { if (unlikely (!resize (len + 1))) -- GitLab