summaryrefslogtreecommitdiff
path: root/thirdparty/harfbuzz/src/hb-map.hh
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/harfbuzz/src/hb-map.hh')
-rw-r--r--thirdparty/harfbuzz/src/hb-map.hh31
1 files changed, 16 insertions, 15 deletions
diff --git a/thirdparty/harfbuzz/src/hb-map.hh b/thirdparty/harfbuzz/src/hb-map.hh
index 92c1bd67e5..dcd5267d74 100644
--- a/thirdparty/harfbuzz/src/hb-map.hh
+++ b/thirdparty/harfbuzz/src/hb-map.hh
@@ -85,7 +85,7 @@ struct hb_hashmap_t
}
void fini_shallow ()
{
- free (items);
+ hb_free (items);
items = nullptr;
population = occupancy = 0;
}
@@ -97,8 +97,6 @@ struct hb_hashmap_t
void reset ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
successful = true;
clear ();
}
@@ -111,7 +109,7 @@ struct hb_hashmap_t
unsigned int power = hb_bit_storage (population * 2 + 8);
unsigned int new_size = 1u << power;
- item_t *new_items = (item_t *) malloc ((size_t) new_size * sizeof (item_t));
+ item_t *new_items = (item_t *) hb_malloc ((size_t) new_size * sizeof (item_t));
if (unlikely (!new_items))
{
successful = false;
@@ -137,14 +135,14 @@ struct hb_hashmap_t
old_items[i].hash,
old_items[i].value);
- free (old_items);
+ hb_free (old_items);
return true;
}
- void set (K key, V value)
+ bool set (K key, V value)
{
- set_with_hash (key, hb_hash (key), value);
+ return set_with_hash (key, hb_hash (key), value);
}
V get (K key) const
@@ -171,8 +169,8 @@ struct hb_hashmap_t
void clear ()
{
- if (unlikely (hb_object_is_immutable (this)))
- return;
+ if (unlikely (!successful)) return;
+
if (items)
for (auto &_ : hb_iter (items, mask + 1))
_.clear ();
@@ -181,6 +179,7 @@ struct hb_hashmap_t
}
bool is_empty () const { return population == 0; }
+ explicit operator bool () const { return !is_empty (); }
unsigned int get_population () const { return population; }
@@ -214,20 +213,20 @@ struct hb_hashmap_t
protected:
- void set_with_hash (K key, uint32_t hash, V value)
+ bool set_with_hash (K key, uint32_t hash, V value)
{
- if (unlikely (!successful)) return;
- if (unlikely (key == kINVALID)) return;
- if ((occupancy + occupancy / 2) >= mask && !resize ()) return;
+ if (unlikely (!successful)) return false;
+ if (unlikely (key == kINVALID)) return true;
+ if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false;
unsigned int i = bucket_for_hash (key, hash);
if (value == vINVALID && items[i].key != key)
- return; /* Trying to delete non-existent key. */
+ return true; /* Trying to delete non-existent key. */
if (!items[i].is_unused ())
{
occupancy--;
- if (items[i].is_tombstone ())
+ if (!items[i].is_tombstone ())
population--;
}
@@ -238,6 +237,8 @@ struct hb_hashmap_t
occupancy++;
if (!items[i].is_tombstone ())
population++;
+
+ return true;
}
unsigned int bucket_for (K key) const