From fa333e34d6230210bc73a88b0ba6df2102dcda51 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 27 Dec 2018 17:56:22 -0500 Subject: [PATCH] [vector] Remove static_array Was good idea, but with C++ types with constructor/destructor, was getting in the way as compiler was destructing those items where it was not desired. Since C++ does not allow zero-sized arrays, just remove it... --- src/hb-aat-map.hh | 4 ++-- src/hb-cff-interp-common.hh | 2 +- src/hb-face.cc | 2 +- src/hb-object.hh | 2 +- src/hb-ot-cff-common.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 2 +- src/hb-ot-map.hh | 10 +++++----- src/hb-ot-post-table.hh | 2 +- src/hb-set.hh | 4 ++-- src/hb-vector.hh | 34 +++++++++++----------------------- src/hb.hh | 3 +++ 11 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/hb-aat-map.hh b/src/hb-aat-map.hh index fa312dbec..3853b7e0d 100644 --- a/src/hb-aat-map.hh +++ b/src/hb-aat-map.hh @@ -44,7 +44,7 @@ struct hb_aat_map_t void fini () { chain_flags.fini (); } public: - hb_vector_t chain_flags; + hb_vector_t chain_flags; }; struct hb_aat_map_builder_t @@ -84,7 +84,7 @@ struct hb_aat_map_builder_t hb_face_t *face; public: - hb_vector_t features; + hb_vector_t features; }; diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index 843256c6b..9a45332b7 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -482,7 +482,7 @@ struct stack_t protected: bool error; unsigned int count; - hb_vector_t elements; + hb_vector_t elements; }; /* argument stack */ diff --git a/src/hb-face.cc b/src/hb-face.cc index 1042d706c..375ef9293 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -599,7 +599,7 @@ struct hb_face_builder_data_t hb_blob_t *blob; }; - hb_vector_t tables; + hb_vector_t tables; }; static hb_face_builder_data_t * diff --git a/src/hb-object.hh b/src/hb-object.hh index adbd3ebc5..68520f2a1 100644 --- a/src/hb-object.hh +++ b/src/hb-object.hh @@ -45,7 +45,7 @@ template struct hb_lockable_set_t { - hb_vector_t items; + hb_vector_t items; void init () { items.init (); } diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 05eaf64cf..3a9cce353 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -61,7 +61,7 @@ struct code_pair_t hb_codepoint_t glyph; }; -typedef hb_vector_t str_buff_t; +typedef hb_vector_t str_buff_t; struct str_buff_vec_t : hb_vector_t { void fini () { SUPER::fini_deep (); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 532cf4b07..dd44e746a 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -643,7 +643,7 @@ struct hb_get_subtables_context_t : hb_set_digest_t digest; }; - typedef hb_vector_t array_t; + typedef hb_vector_t array_t; /* Dispatch interface. */ const char *get_name () { return "GET_SUBTABLES"; } diff --git a/src/hb-ot-map.hh b/src/hb-ot-map.hh index 9c55864dc..28407c217 100644 --- a/src/hb-ot-map.hh +++ b/src/hb-ot-map.hh @@ -167,9 +167,9 @@ struct hb_ot_map_t hb_mask_t global_mask; - hb_vector_t features; - hb_vector_t lookups[2]; /* GSUB/GPOS */ - hb_vector_t stages[2]; /* GSUB/GPOS */ + hb_vector_t features; + hb_vector_t lookups[2]; /* GSUB/GPOS */ + hb_vector_t stages[2]; /* GSUB/GPOS */ }; enum hb_ot_map_feature_flags_t @@ -275,8 +275,8 @@ struct hb_ot_map_builder_t private: unsigned int current_stage[2]; /* GSUB/GPOS */ - hb_vector_t feature_infos; - hb_vector_t stages[2]; /* GSUB/GPOS */ + hb_vector_t feature_infos; + hb_vector_t stages[2]; /* GSUB/GPOS */ }; diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 6c8eb180f..a799b869f 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -241,7 +241,7 @@ struct post hb_blob_ptr_t table; uint32_t version; const ArrayOf *glyphNameIndex; - hb_vector_t index_to_offset; + hb_vector_t index_to_offset; const uint8_t *pool; hb_atomic_ptr_t gids_sorted_by_name; }; diff --git a/src/hb-set.hh b/src/hb-set.hh index 725fa3393..990c2953c 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -186,8 +186,8 @@ struct hb_set_t hb_object_header_t header; bool successful; /* Allocations successful */ mutable unsigned int population; - hb_vector_t page_map; - hb_vector_t pages; + hb_vector_t page_map; + hb_vector_t pages; void init_shallow () { diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 9aa930989..7d615bf6a 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -32,13 +32,13 @@ #include "hb-null.hh" -template +template struct hb_vector_t { typedef Type item_t; enum { item_size = hb_static_size (Type) }; - HB_NO_COPY_ASSIGN_TEMPLATE2 (hb_vector_t, Type, PreallocedCount); + HB_NO_COPY_ASSIGN_TEMPLATE (hb_vector_t, Type); hb_vector_t () { init (); } ~hb_vector_t () { fini (); } @@ -46,13 +46,11 @@ struct hb_vector_t private: int allocated; /* == -1 means allocation failed. */ Type *arrayZ_; - Type static_array[PreallocedCount]; public: void init () { - length = 0; - allocated = ARRAY_LENGTH (static_array); + allocated = length = 0; arrayZ_ = nullptr; } @@ -71,8 +69,8 @@ struct hb_vector_t fini (); } - const Type * arrayZ () const { return arrayZ_ ? arrayZ_ : static_array; } - Type * arrayZ () { return arrayZ_ ? arrayZ_ : static_array; } + const Type * arrayZ () const { return arrayZ_; } + Type * arrayZ () { return arrayZ_; } Type& operator [] (int i_) { @@ -158,22 +156,12 @@ struct hb_vector_t new_allocated += (new_allocated >> 1) + 8; Type *new_array = nullptr; - - if (!arrayZ_) - { - new_array = (Type *) calloc (new_allocated, sizeof (Type)); - if (new_array) - memcpy (new_array, static_array, length * sizeof (Type)); - } - else - { - bool overflows = - (int) new_allocated < 0 || - (new_allocated < allocated) || - hb_unsigned_mul_overflows (new_allocated, sizeof (Type)); - if (likely (!overflows)) - new_array = (Type *) realloc (arrayZ_, new_allocated * sizeof (Type)); - } + bool overflows = + (int) new_allocated < 0 || + (new_allocated < allocated) || + hb_unsigned_mul_overflows (new_allocated, sizeof (Type)); + if (likely (!overflows)) + new_array = (Type *) realloc (arrayZ_, new_allocated * sizeof (Type)); if (unlikely (!new_array)) { diff --git a/src/hb.hh b/src/hb.hh index d604d958e..c6db70aed 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -377,6 +377,9 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); #define HB_NO_COPY_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) +#define HB_NO_COPY_ASSIGN_TEMPLATE(TypeName, T) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) #define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ TypeName(const TypeName&); \ void operator=(const TypeName&)