freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 4d5046847: [sfnt] Use faster macros in checksums.


From: Werner Lemberg
Subject: [freetype2] master 4d5046847: [sfnt] Use faster macros in checksums.
Date: Wed, 1 May 2024 23:29:03 -0400 (EDT)

branch: master
commit 4d504684789dc6f8f452aaa4df04f96f31082345
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [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 | 11 +++++++----
 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();
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]