[map] Allow storing classes in the hashmap
Fixes https://github.com/harfbuzz/harfbuzz/issues/3293 The trick was to change the type of the invalid key/value to be non-class.
This commit is contained in:
parent
cba17fd101
commit
394f772937
|
@ -35,8 +35,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename K, typename V,
|
template <typename K, typename V,
|
||||||
K kINVALID = hb_is_pointer (K) ? 0 : std::is_signed<K>::value ? hb_int_min (K) : (K) -1,
|
typename k_invalid_t = K,
|
||||||
V vINVALID = hb_is_pointer (V) ? 0 : std::is_signed<V>::value ? hb_int_min (V) : (V) -1>
|
typename v_invalid_t = V,
|
||||||
|
k_invalid_t kINVALID = hb_is_pointer (K) ? 0 : std::is_signed<K>::value ? hb_int_min (K) : (K) -1,
|
||||||
|
v_invalid_t vINVALID = hb_is_pointer (V) ? 0 : std::is_signed<V>::value ? hb_int_min (V) : (V) -1>
|
||||||
struct hb_hashmap_t
|
struct hb_hashmap_t
|
||||||
{
|
{
|
||||||
static constexpr K INVALID_KEY = kINVALID;
|
static constexpr K INVALID_KEY = kINVALID;
|
||||||
|
@ -62,8 +64,10 @@ struct hb_hashmap_t
|
||||||
hb_copy (o, *this);
|
hb_copy (o, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert (std::is_integral<K>::value || hb_is_pointer (K), "");
|
static_assert (std::is_trivially_copyable<K>::value, "");
|
||||||
static_assert (std::is_integral<V>::value || hb_is_pointer (V), "");
|
static_assert (std::is_trivially_copyable<V>::value, "");
|
||||||
|
static_assert (std::is_trivially_destructible<K>::value, "");
|
||||||
|
static_assert (std::is_trivially_destructible<V>::value, "");
|
||||||
|
|
||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
|
@ -347,20 +351,24 @@ struct hb_hashmap_t
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct hb_map_t : hb_hashmap_t<hb_codepoint_t,
|
struct hb_map_t : hb_hashmap_t<hb_codepoint_t,
|
||||||
|
hb_codepoint_t,
|
||||||
|
hb_codepoint_t,
|
||||||
hb_codepoint_t,
|
hb_codepoint_t,
|
||||||
HB_MAP_VALUE_INVALID,
|
HB_MAP_VALUE_INVALID,
|
||||||
HB_MAP_VALUE_INVALID>
|
HB_MAP_VALUE_INVALID>
|
||||||
{
|
{
|
||||||
using hashmap = hb_hashmap_t<hb_codepoint_t,
|
using hashmap = hb_hashmap_t<hb_codepoint_t,
|
||||||
|
hb_codepoint_t,
|
||||||
|
hb_codepoint_t,
|
||||||
hb_codepoint_t,
|
hb_codepoint_t,
|
||||||
HB_MAP_VALUE_INVALID,
|
HB_MAP_VALUE_INVALID,
|
||||||
HB_MAP_VALUE_INVALID>;
|
HB_MAP_VALUE_INVALID>;
|
||||||
|
|
||||||
hb_map_t () = default;
|
hb_map_t () = default;
|
||||||
~hb_map_t () = default;
|
~hb_map_t () = default;
|
||||||
hb_map_t (hb_map_t& o) = default;
|
hb_map_t (hb_map_t&) = default;
|
||||||
hb_map_t& operator= (const hb_map_t& other) = default;
|
hb_map_t& operator= (const hb_map_t&) = default;
|
||||||
hb_map_t& operator= (hb_map_t&& other) = default;
|
hb_map_t& operator= (hb_map_t&&) = default;
|
||||||
hb_map_t (std::initializer_list<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> lst) : hashmap (lst) {}
|
hb_map_t (std::initializer_list<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> lst) : hashmap (lst) {}
|
||||||
template <typename Iterable,
|
template <typename Iterable,
|
||||||
hb_requires (hb_is_iterable (Iterable))>
|
hb_requires (hb_is_iterable (Iterable))>
|
||||||
|
|
|
@ -98,7 +98,7 @@ static void ClassDef_remap_and_serialize (hb_serialize_context_t *c,
|
||||||
struct hb_prune_langsys_context_t
|
struct hb_prune_langsys_context_t
|
||||||
{
|
{
|
||||||
hb_prune_langsys_context_t (const void *table_,
|
hb_prune_langsys_context_t (const void *table_,
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *script_langsys_map_,
|
hb_hashmap_t<unsigned, hb_set_t *> *script_langsys_map_,
|
||||||
const hb_map_t *duplicate_feature_map_,
|
const hb_map_t *duplicate_feature_map_,
|
||||||
hb_set_t *new_collected_feature_indexes_)
|
hb_set_t *new_collected_feature_indexes_)
|
||||||
:table (table_),
|
:table (table_),
|
||||||
|
@ -137,7 +137,7 @@ struct hb_prune_langsys_context_t
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const void *table;
|
const void *table;
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *script_langsys_map;
|
hb_hashmap_t<unsigned, hb_set_t *> *script_langsys_map;
|
||||||
const hb_map_t *duplicate_feature_map;
|
const hb_map_t *duplicate_feature_map;
|
||||||
hb_set_t *new_feature_indexes;
|
hb_set_t *new_feature_indexes;
|
||||||
|
|
||||||
|
@ -179,14 +179,14 @@ struct hb_subset_layout_context_t :
|
||||||
hb_subset_context_t *subset_context;
|
hb_subset_context_t *subset_context;
|
||||||
const hb_tag_t table_tag;
|
const hb_tag_t table_tag;
|
||||||
const hb_map_t *lookup_index_map;
|
const hb_map_t *lookup_index_map;
|
||||||
const hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *script_langsys_map;
|
const hb_hashmap_t<unsigned, hb_set_t *> *script_langsys_map;
|
||||||
const hb_map_t *feature_index_map;
|
const hb_map_t *feature_index_map;
|
||||||
unsigned cur_script_index;
|
unsigned cur_script_index;
|
||||||
|
|
||||||
hb_subset_layout_context_t (hb_subset_context_t *c_,
|
hb_subset_layout_context_t (hb_subset_context_t *c_,
|
||||||
hb_tag_t tag_,
|
hb_tag_t tag_,
|
||||||
hb_map_t *lookup_map_,
|
hb_map_t *lookup_map_,
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *script_langsys_map_,
|
hb_hashmap_t<unsigned, hb_set_t *> *script_langsys_map_,
|
||||||
hb_map_t *feature_index_map_) :
|
hb_map_t *feature_index_map_) :
|
||||||
subset_context (c_),
|
subset_context (c_),
|
||||||
table_tag (tag_),
|
table_tag (tag_),
|
||||||
|
|
|
@ -163,7 +163,7 @@ struct hb_closure_context_t :
|
||||||
hb_set_t *glyphs_,
|
hb_set_t *glyphs_,
|
||||||
hb_set_t *cur_intersected_glyphs_,
|
hb_set_t *cur_intersected_glyphs_,
|
||||||
hb_map_t *done_lookups_glyph_count_,
|
hb_map_t *done_lookups_glyph_count_,
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *done_lookups_glyph_set_,
|
hb_hashmap_t<unsigned, hb_set_t *> *done_lookups_glyph_set_,
|
||||||
unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
|
unsigned int nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
|
||||||
face (face_),
|
face (face_),
|
||||||
glyphs (glyphs_),
|
glyphs (glyphs_),
|
||||||
|
@ -192,7 +192,7 @@ struct hb_closure_context_t :
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hb_map_t *done_lookups_glyph_count;
|
hb_map_t *done_lookups_glyph_count;
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *done_lookups_glyph_set;
|
hb_hashmap_t<unsigned, hb_set_t *> *done_lookups_glyph_set;
|
||||||
unsigned int lookup_count;
|
unsigned int lookup_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3631,7 +3631,7 @@ struct GSUBGPOS
|
||||||
}
|
}
|
||||||
|
|
||||||
void prune_langsys (const hb_map_t *duplicate_feature_map,
|
void prune_langsys (const hb_map_t *duplicate_feature_map,
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *script_langsys_map,
|
hb_hashmap_t<unsigned, hb_set_t *> *script_langsys_map,
|
||||||
hb_set_t *new_feature_indexes /* OUT */) const
|
hb_set_t *new_feature_indexes /* OUT */) const
|
||||||
{
|
{
|
||||||
hb_prune_langsys_context_t c (this, script_langsys_map, duplicate_feature_map, new_feature_indexes);
|
hb_prune_langsys_context_t c (this, script_langsys_map, duplicate_feature_map, new_feature_indexes);
|
||||||
|
@ -3689,7 +3689,7 @@ struct GSUBGPOS
|
||||||
hb_map_t *duplicate_feature_map /* OUT */) const
|
hb_map_t *duplicate_feature_map /* OUT */) const
|
||||||
{
|
{
|
||||||
if (feature_indices->is_empty ()) return;
|
if (feature_indices->is_empty ()) return;
|
||||||
hb_hashmap_t<hb_tag_t, hb_set_t *, (unsigned)-1, nullptr> unique_features;
|
hb_hashmap_t<hb_tag_t, hb_set_t *> unique_features;
|
||||||
//find out duplicate features after subset
|
//find out duplicate features after subset
|
||||||
for (unsigned i : feature_indices->iter ())
|
for (unsigned i : feature_indices->iter ())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1493,7 +1493,7 @@ hb_ot_layout_lookup_substitute_closure (hb_face_t *face,
|
||||||
{
|
{
|
||||||
hb_set_t cur_intersected_glyphs;
|
hb_set_t cur_intersected_glyphs;
|
||||||
hb_map_t done_lookups_glyph_count;
|
hb_map_t done_lookups_glyph_count;
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> done_lookups_glyph_set;
|
hb_hashmap_t<unsigned, hb_set_t *> done_lookups_glyph_set;
|
||||||
OT::hb_closure_context_t c (face, glyphs, &cur_intersected_glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
|
OT::hb_closure_context_t c (face, glyphs, &cur_intersected_glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
|
||||||
|
|
||||||
const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
|
const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index);
|
||||||
|
@ -1522,7 +1522,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
|
||||||
{
|
{
|
||||||
hb_set_t cur_intersected_glyphs;
|
hb_set_t cur_intersected_glyphs;
|
||||||
hb_map_t done_lookups_glyph_count;
|
hb_map_t done_lookups_glyph_count;
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> done_lookups_glyph_set;
|
hb_hashmap_t<unsigned, hb_set_t *> done_lookups_glyph_set;
|
||||||
OT::hb_closure_context_t c (face, glyphs, &cur_intersected_glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
|
OT::hb_closure_context_t c (face, glyphs, &cur_intersected_glyphs, &done_lookups_glyph_count, &done_lookups_glyph_set);
|
||||||
const OT::GSUB& gsub = *face->table.GSUB->table;
|
const OT::GSUB& gsub = *face->table.GSUB->table;
|
||||||
|
|
||||||
|
|
|
@ -652,7 +652,9 @@ struct hb_serialize_context_t
|
||||||
hb_vector_t<object_t *> packed;
|
hb_vector_t<object_t *> packed;
|
||||||
|
|
||||||
/* Map view of packed objects. */
|
/* Map view of packed objects. */
|
||||||
hb_hashmap_t<const object_t *, objidx_t, nullptr, 0> packed_map;
|
hb_hashmap_t<const object_t *, objidx_t,
|
||||||
|
const object_t *, objidx_t,
|
||||||
|
nullptr, 0> packed_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HB_SERIALIZE_HH */
|
#endif /* HB_SERIALIZE_HH */
|
||||||
|
|
|
@ -157,9 +157,9 @@ struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t>
|
||||||
{
|
{
|
||||||
hb_set_t () = default;
|
hb_set_t () = default;
|
||||||
~hb_set_t () = default;
|
~hb_set_t () = default;
|
||||||
hb_set_t (hb_set_t& o) = default;
|
hb_set_t (hb_set_t&) = default;
|
||||||
hb_set_t& operator= (const hb_set_t& other) = default;
|
hb_set_t& operator= (const hb_set_t&) = default;
|
||||||
hb_set_t& operator= (hb_set_t&& other) = default;
|
hb_set_t& operator= (hb_set_t&&) = default;
|
||||||
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : hb_sparseset_t<hb_bit_set_invertible_t> (lst) {}
|
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : hb_sparseset_t<hb_bit_set_invertible_t> (lst) {}
|
||||||
template <typename Iterable,
|
template <typename Iterable,
|
||||||
hb_requires (hb_is_iterable (Iterable))>
|
hb_requires (hb_is_iterable (Iterable))>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "hb-ot-math-table.hh"
|
#include "hb-ot-math-table.hh"
|
||||||
|
|
||||||
|
|
||||||
typedef hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> script_langsys_map;
|
typedef hb_hashmap_t<unsigned, hb_set_t *> script_langsys_map;
|
||||||
#ifndef HB_NO_SUBSET_CFF
|
#ifndef HB_NO_SUBSET_CFF
|
||||||
static inline void
|
static inline void
|
||||||
_add_cff_seac_components (const OT::cff1::accelerator_t &cff,
|
_add_cff_seac_components (const OT::cff1::accelerator_t &cff,
|
||||||
|
|
|
@ -84,8 +84,8 @@ struct hb_subset_plan_t
|
||||||
hb_map_t *gpos_lookups;
|
hb_map_t *gpos_lookups;
|
||||||
|
|
||||||
//active langsys we'd like to retain
|
//active langsys we'd like to retain
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *gsub_langsys;
|
hb_hashmap_t<unsigned, hb_set_t *> *gsub_langsys;
|
||||||
hb_hashmap_t<unsigned, hb_set_t *, (unsigned)-1, nullptr> *gpos_langsys;
|
hb_hashmap_t<unsigned, hb_set_t *> *gpos_langsys;
|
||||||
|
|
||||||
//active features after removing redundant langsys and prune_features
|
//active features after removing redundant langsys and prune_features
|
||||||
hb_map_t *gsub_features;
|
hb_map_t *gsub_features;
|
||||||
|
|
|
@ -98,5 +98,12 @@ main (int argc, char **argv)
|
||||||
assert (v2.get_population () == 2);
|
assert (v2.get_population () == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test class key / value types. */
|
||||||
|
{
|
||||||
|
hb_hashmap_t<hb_bytes_t, int, nullptr_t, int, nullptr, 0> m1;
|
||||||
|
hb_hashmap_t<int, hb_bytes_t, int, nullptr_t, 0, nullptr> m2;
|
||||||
|
hb_hashmap_t<hb_bytes_t, hb_bytes_t, nullptr_t, nullptr_t, nullptr, nullptr> m3;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue