diff --git a/src/hb-alloc-pool.hh b/src/hb-alloc-pool.hh index 089f87fae..efa7e5214 100644 --- a/src/hb-alloc-pool.hh +++ b/src/hb-alloc-pool.hh @@ -88,6 +88,14 @@ struct hb_alloc_pool_t return ret; } + void discard (void *p_, size_t size) + { + // Reclaim memory if we can. + char *p = (char *) p_; + if (current_chunk.arrayZ == p + size && current_chunk.backwards_length >= size) + current_chunk -= size; + } + private: hb_vector_t> chunks; hb_array_t current_chunk; diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 1881251fa..a8c8858e5 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -523,7 +523,7 @@ struct tuple_delta_t o->tupleIndex = flag; unsigned total_header_len = 4 + (peak_count + interim_count) * (F2DOT14::static_size); - compiled_tuple_header.shrink (total_header_len, false); + compiled_tuple_header.shrink_back_to_pool (pool, total_header_len); return true; } @@ -600,7 +600,7 @@ struct tuple_delta_t if (j != rounded_deltas.length) return false; encoded_len += compile_deltas (compiled_deltas.as_array ().sub_array (encoded_len), rounded_deltas); } - compiled_deltas.shrink (encoded_len, false); + compiled_deltas.shrink_back_to_pool (pool, encoded_len); return true; } diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 272a0129a..dc34f4155 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -574,6 +574,17 @@ struct hb_vector_t return true; } + template + void shrink_back_to_pool (allocator_t *allocator, int size) + { + unsigned orig_length = length; + + shrink (size, false); + + if (allocator && !is_owned ()) + allocator->discard (arrayZ + length, (orig_length - length) * sizeof (Type)); + } + HB_ALWAYS_INLINE_VECTOR_ALLOCS bool resize_full (int size_, bool initialize, bool exact) {