From 8bb1a3ce9ae8a24c168a51c6faf16779561138ae Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 15:38:40 -0600 Subject: [PATCH] [cff-common] Write INDEX offset-size calc using hb_bit_storage() --- src/hb-ot-cff-common.hh | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index a882dba5e..88f2d7e4f 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -46,19 +46,6 @@ template static inline const Type& StructAtOffsetOrNull (const void *P, unsigned int offset) { return offset ? StructAtOffset (P, offset) : Null (Type); } -inline unsigned int calcOffSize (unsigned int dataSize) -{ - unsigned int size = 1; - unsigned int offset = dataSize + 1; - while (offset & ~0xFF) - { - size++; - offset >>= 8; - } - /* format does not support size > 4; caller should handle it as an error */ - return size; -} - struct code_pair_t { hb_codepoint_t code; @@ -197,7 +184,7 @@ struct CFFIndex TRACE_SERIALIZE (this); unsigned total = + it | hb_reduce (hb_add, 0); - unsigned off_size = calcOffSize (total); + unsigned off_size = (hb_bit_storage (total + 1) + 7) / 8; /* serialize CFFIndex header */ if (unlikely (!c->extend_min (this))) return_trace (false);