From b238578a9c9255282b7634bcbf751f03001ceda6 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 21 Nov 2022 14:36:57 -0700 Subject: [PATCH] [cff] Optimize INDEX operator[] --- src/hb-ot-cff-common.hh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 2d9af7865..f794ef890 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -207,10 +207,14 @@ struct CFFIndex unsigned int size = offSize; const HBUINT8 *p = offsets + size * index; - unsigned int offset = 0; - for (; size; size--) - offset = (offset << 8) + *p++; - return offset; + switch (size) + { + case 1: return * (HBUINT8 *) p; + case 2: return * (HBUINT16 *) p; + case 3: return * (HBUINT24 *) p; + case 4: return * (HBUINT32 *) p; + default: return 0; + } } unsigned int length_at (unsigned int index) const