From 4d504684789dc6f8f452aaa4df04f96f31082345 Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Wed, 1 May 2024 23:19:31 -0400 Subject: [PATCH] [sfnt] Use faster macros in checksums. * src/truetype/ttobjs.c (tt_synth_sfnt_checksum): Use FT_NEXT_XXX. * src/sfnt/sfwoff2.c (compute_ULong_sum): Use macros. --- src/sfnt/sfwoff2.c | 10 ++++------ src/truetype/ttobjs.c | 13 ++++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/sfnt/sfwoff2.c b/src/sfnt/sfwoff2.c index 1ddbb247e..3df4d2664 100644 --- a/src/sfnt/sfwoff2.c +++ b/src/sfnt/sfwoff2.c @@ -289,17 +289,15 @@ FT_ULong checksum = 0; FT_ULong aligned_size = size & ~3UL; FT_ULong i; + FT_Int shift; for ( i = 0; i < aligned_size; i += 4 ) - checksum += ( (FT_ULong)buf[i ] << 24 ) | - ( (FT_ULong)buf[i + 1] << 16 ) | - ( (FT_ULong)buf[i + 2] << 8 ) | - ( (FT_ULong)buf[i + 3] << 0 ); + checksum += FT_NEXT_ULONG( buf ); /* remaining bytes can be shifted and added one at a time */ - for ( ; i < size; ++i ) - checksum += (FT_ULong)buf[i] << ( 24 - 8 * ( i & 3 ) ); + for ( shift = 24; i < size; i++, shift -= 8 ) + checksum += (FT_UInt32)FT_NEXT_BYTE( buf ) << shift; return checksum; } diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index 3cdbfff1b..05489d732 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -256,17 +256,20 @@ { FT_Error error; FT_UInt32 checksum = 0; - FT_UInt i; + FT_Byte* p; + FT_Int shift; if ( FT_FRAME_ENTER( length ) ) return 0; - for ( ; length > 3; length -= 4 ) - checksum += (FT_UInt32)FT_GET_ULONG(); + p = (FT_Byte*)stream->cursor; - for ( i = 3; length > 0; length--, i-- ) - checksum += (FT_UInt32)FT_GET_BYTE() << ( i * 8 ); + for ( ; length > 3; length -= 4 ) + checksum += FT_NEXT_ULONG( p ); + + for ( shift = 24; length > 0; length--, shift -=8 ) + checksum += (FT_UInt32)FT_NEXT_BYTE( p ) << shift; FT_FRAME_EXIT();