aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2024-05-01 23:19:31 -0400
committerAlexei Podtelezhnikov <apodtele@gmail.com>2024-05-01 23:19:31 -0400
commit4d504684789dc6f8f452aaa4df04f96f31082345 (patch)
tree5a8345488636ba1a275a9b712b70fa222d45d9f9
parent13da9042676e6ff824c725f490b7559194f7dc9c (diff)
downloadfreetype-4d504684789dc6f8f452aaa4df04f96f31082345.tar.gz
[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.
-rw-r--r--src/sfnt/sfwoff2.c10
-rw-r--r--src/truetype/ttobjs.c11
2 files changed, 11 insertions, 10 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;
+ p = (FT_Byte*)stream->cursor;
+
for ( ; length > 3; length -= 4 )
- checksum += (FT_UInt32)FT_GET_ULONG();
+ checksum += FT_NEXT_ULONG( p );
- for ( i = 3; length > 0; length--, i-- )
- checksum += (FT_UInt32)FT_GET_BYTE() << ( i * 8 );
+ for ( shift = 24; length > 0; length--, shift -=8 )
+ checksum += (FT_UInt32)FT_NEXT_BYTE( p ) << shift;
FT_FRAME_EXIT();