From 9033c7f99d5ffe80c349a2ed5e4ef68ca4bed434 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 May 2022 14:58:53 -0600 Subject: [PATCH] [cff-common] Optimize INDEX::operator[] Previous try showed slowdown in benchmarks, suprisingly. Rewrite it keeping the function, hopefully allowing better optimization. --- src/hb-ot-cff-common.hh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 8688575e9..d115fd2e0 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -214,10 +214,11 @@ struct CFFIndex unsigned int length_at (unsigned int index) const { - if (unlikely ((offset_at (index + 1) < offset_at (index)) || - (offset_at (index + 1) > offset_at (count)))) + unsigned offset0 = offset_at (index); + unsigned offset1 = offset_at (index + 1); + if (unlikely (offset1 < offset0 || offset1 > offset_at (count))) return 0; - return offset_at (index + 1) - offset_at (index); + return offset1 - offset0; } const unsigned char *data_base () const