diff options
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-pool.hh')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/hb-pool.hh | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-pool.hh b/src/3rdparty/harfbuzz-ng/src/hb-pool.hh index 83875dbe13..fcf10666b0 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-pool.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-pool.hh @@ -29,23 +29,28 @@ #include "hb.hh" -/* Memory pool for persistent allocation of small objects. */ - -template <typename T, unsigned ChunkLen = 16> +/* Memory pool for persistent allocation of small objects. + * + * Some AI musings on this, not necessarily true: + * + * This is a very simple implementation, but it's good enough for our + * purposes. It's not thread-safe. It's not very fast. It's not + * very memory efficient. It's not very cache efficient. It's not + * very anything efficient. But it's simple and it works. And it's + * good enough for our purposes. If you need something more + * sophisticated, use a real allocator. Or use a real language. */ + +template <typename T, unsigned ChunkLen = 32> struct hb_pool_t { hb_pool_t () : next (nullptr) {} - ~hb_pool_t () { fini (); } - - void fini () + ~hb_pool_t () { next = nullptr; + hb_iter (chunks) - | hb_apply ([] (chunk_t *_) { ::free (_); }) + | hb_apply (hb_free) ; - - chunks.fini (); } T* alloc () @@ -53,7 +58,7 @@ struct hb_pool_t if (unlikely (!next)) { if (unlikely (!chunks.alloc (chunks.length + 1))) return nullptr; - chunk_t *chunk = (chunk_t *) calloc (1, sizeof (chunk_t)); + chunk_t *chunk = (chunk_t *) hb_malloc (sizeof (chunk_t)); if (unlikely (!chunk)) return nullptr; chunks.push (chunk); next = chunk->thread (); @@ -62,12 +67,12 @@ struct hb_pool_t T* obj = next; next = * ((T**) next); - memset (obj, 0, sizeof (T)); + hb_memset (obj, 0, sizeof (T)); return obj; } - void free (T* obj) + void release (T* obj) { * (T**) obj = next; next = obj; |