freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [sfnt] Clean up CMAP{4,12,13} handling.


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [sfnt] Clean up CMAP{4,12,13} handling.
Date: Sun, 09 Apr 2023 03:33:28 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • d2544433
    by Alexei Podtelezhnikov at 2023-04-08T23:15:41-04:00
    [sfnt] Clean up CMAP{4,12,13} handling.
    
    This moves the charcode overflow checks upstream and turns some
    while-loops into the do-while ones to avoid the uninitialized warnings.
    This should slightly reduce the number of checks and jumps.
    
    * src/sfnt/ttcmap.c (tt_cmap{4,12,13}_next,
    tt_cmap{4.12.13}_char_map_linear): Remove the charcode overflow check.
    (tt_cmap{4,12,13}_char_map_binary): Ditto and use do-while.
    (tt_cmap{12,13}_char_next): Add the overflow check.
    

1 changed file:

Changes:

  • src/sfnt/ttcmap.c
    ... ... @@ -794,9 +794,6 @@
    794 794
         FT_UInt  charcode;
    
    795 795
     
    
    796 796
     
    
    797
    -    if ( cmap->cur_charcode >= 0xFFFFUL )
    
    798
    -      goto Fail;
    
    799
    -
    
    800 797
         charcode = (FT_UInt)cmap->cur_charcode + 1;
    
    801 798
     
    
    802 799
         if ( charcode < cmap->cur_start )
    
    ... ... @@ -882,7 +879,6 @@
    882 879
             charcode = cmap->cur_start;
    
    883 880
         }
    
    884 881
     
    
    885
    -  Fail:
    
    886 882
         cmap->cur_charcode = (FT_UInt32)0xFFFFFFFFUL;
    
    887 883
         cmap->cur_gindex   = 0;
    
    888 884
       }
    
    ... ... @@ -1104,25 +1100,19 @@
    1104 1100
         FT_UInt    num_segs2, start, end, offset;
    
    1105 1101
         FT_Int     delta;
    
    1106 1102
         FT_UInt    i, num_segs;
    
    1107
    -    FT_UInt32  charcode = *pcharcode;
    
    1103
    +    FT_UInt32  charcode = *pcharcode + next;
    
    1108 1104
         FT_UInt    gindex   = 0;
    
    1109 1105
         FT_Byte*   p;
    
    1110 1106
         FT_Byte*   q;
    
    1111 1107
     
    
    1112 1108
     
    
    1113 1109
         p = cmap->data + 6;
    
    1114
    -    num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 );
    
    1115
    -
    
    1116
    -    num_segs = num_segs2 >> 1;
    
    1110
    +    num_segs = TT_PEEK_USHORT( p ) >> 1;
    
    1117 1111
     
    
    1118 1112
         if ( !num_segs )
    
    1119 1113
           return 0;
    
    1120 1114
     
    
    1121
    -    if ( next )
    
    1122
    -      charcode++;
    
    1123
    -
    
    1124
    -    if ( charcode > 0xFFFFU )
    
    1125
    -      return 0;
    
    1115
    +    num_segs2 = num_segs << 1;
    
    1126 1116
     
    
    1127 1117
         /* linear search */
    
    1128 1118
         p = cmap->data + 14;               /* ends table   */
    
    ... ... @@ -1238,31 +1228,24 @@
    1238 1228
         FT_UInt   num_segs2, start, end, offset;
    
    1239 1229
         FT_Int    delta;
    
    1240 1230
         FT_UInt   max, min, mid, num_segs;
    
    1241
    -    FT_UInt   charcode = (FT_UInt)*pcharcode;
    
    1231
    +    FT_UInt   charcode = (FT_UInt)*pcharcode + next;
    
    1242 1232
         FT_UInt   gindex   = 0;
    
    1243 1233
         FT_Byte*  p;
    
    1244 1234
     
    
    1245 1235
     
    
    1246 1236
         p = cmap->data + 6;
    
    1247
    -    num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 );
    
    1237
    +    num_segs = TT_PEEK_USHORT( p ) >> 1;
    
    1248 1238
     
    
    1249
    -    if ( !num_segs2 )
    
    1239
    +    if ( !num_segs )
    
    1250 1240
           return 0;
    
    1251 1241
     
    
    1252
    -    num_segs = num_segs2 >> 1;
    
    1253
    -
    
    1254
    -    /* make compiler happy */
    
    1255
    -    mid = num_segs;
    
    1256
    -    end = 0xFFFFU;
    
    1257
    -
    
    1258
    -    if ( next )
    
    1259
    -      charcode++;
    
    1242
    +    num_segs2 = num_segs << 1;
    
    1260 1243
     
    
    1261 1244
         min = 0;
    
    1262 1245
         max = num_segs;
    
    1263 1246
     
    
    1264 1247
         /* binary search */
    
    1265
    -    while ( min < max )
    
    1248
    +    do
    
    1266 1249
         {
    
    1267 1250
           mid    = ( min + max ) >> 1;
    
    1268 1251
           p      = cmap->data + 14 + mid * 2;
    
    ... ... @@ -1445,6 +1428,7 @@
    1445 1428
             break;
    
    1446 1429
           }
    
    1447 1430
         }
    
    1431
    +    while ( min < max );
    
    1448 1432
     
    
    1449 1433
         if ( next )
    
    1450 1434
         {
    
    ... ... @@ -1454,12 +1438,8 @@
    1454 1438
           /* if `charcode' is not in any segment, then `mid' is */
    
    1455 1439
           /* the segment nearest to `charcode'                  */
    
    1456 1440
     
    
    1457
    -      if ( charcode > end )
    
    1458
    -      {
    
    1459
    -        mid++;
    
    1460
    -        if ( mid == num_segs )
    
    1461
    -          return 0;
    
    1462
    -      }
    
    1441
    +      if ( charcode > end && ++mid == num_segs )
    
    1442
    +        return 0;
    
    1463 1443
     
    
    1464 1444
           if ( tt_cmap4_set_range( cmap4, mid ) )
    
    1465 1445
           {
    
    ... ... @@ -1474,7 +1454,6 @@
    1474 1454
               cmap4->cur_gindex = gindex;
    
    1475 1455
             else
    
    1476 1456
             {
    
    1477
    -          cmap4->cur_charcode = charcode;
    
    1478 1457
               tt_cmap4_next( cmap4 );
    
    1479 1458
               gindex = cmap4->cur_gindex;
    
    1480 1459
             }
    
    ... ... @@ -2340,9 +2319,6 @@
    2340 2319
         FT_UInt   gindex;
    
    2341 2320
     
    
    2342 2321
     
    
    2343
    -    if ( cmap->cur_charcode >= 0xFFFFFFFFUL )
    
    2344
    -      goto Fail;
    
    2345
    -
    
    2346 2322
         char_code = cmap->cur_charcode + 1;
    
    2347 2323
     
    
    2348 2324
         for ( n = cmap->cur_group; n < cmap->num_groups; n++ )
    
    ... ... @@ -2400,7 +2376,7 @@
    2400 2376
         FT_UInt    gindex     = 0;
    
    2401 2377
         FT_Byte*   p          = cmap->data + 12;
    
    2402 2378
         FT_UInt32  num_groups = TT_PEEK_ULONG( p );
    
    2403
    -    FT_UInt32  char_code  = *pchar_code;
    
    2379
    +    FT_UInt32  char_code  = *pchar_code + next;
    
    2404 2380
         FT_UInt32  start, end, start_id;
    
    2405 2381
         FT_UInt32  max, min, mid;
    
    2406 2382
     
    
    ... ... @@ -2408,23 +2384,11 @@
    2408 2384
         if ( !num_groups )
    
    2409 2385
           return 0;
    
    2410 2386
     
    
    2411
    -    /* make compiler happy */
    
    2412
    -    mid = num_groups;
    
    2413
    -    end = 0xFFFFFFFFUL;
    
    2414
    -
    
    2415
    -    if ( next )
    
    2416
    -    {
    
    2417
    -      if ( char_code >= 0xFFFFFFFFUL )
    
    2418
    -        return 0;
    
    2419
    -
    
    2420
    -      char_code++;
    
    2421
    -    }
    
    2422
    -
    
    2423 2387
         min = 0;
    
    2424 2388
         max = num_groups;
    
    2425 2389
     
    
    2426 2390
         /* binary search */
    
    2427
    -    while ( min < max )
    
    2391
    +    do
    
    2428 2392
         {
    
    2429 2393
           mid = ( min + max ) >> 1;
    
    2430 2394
           p   = cmap->data + 16 + 12 * mid;
    
    ... ... @@ -2448,6 +2412,7 @@
    2448 2412
             break;
    
    2449 2413
           }
    
    2450 2414
         }
    
    2415
    +    while ( min < max );
    
    2451 2416
     
    
    2452 2417
         if ( next )
    
    2453 2418
         {
    
    ... ... @@ -2458,12 +2423,8 @@
    2458 2423
           /* if `char_code' is not in any group, then `mid' is */
    
    2459 2424
           /* the group nearest to `char_code'                  */
    
    2460 2425
     
    
    2461
    -      if ( char_code > end )
    
    2462
    -      {
    
    2463
    -        mid++;
    
    2464
    -        if ( mid == num_groups )
    
    2465
    -          return 0;
    
    2466
    -      }
    
    2426
    +      if ( char_code > end && ++mid == num_groups )
    
    2427
    +        return 0;
    
    2467 2428
     
    
    2468 2429
           cmap12->valid        = 1;
    
    2469 2430
           cmap12->cur_charcode = char_code;
    
    ... ... @@ -2505,6 +2466,9 @@
    2505 2466
         FT_UInt    gindex;
    
    2506 2467
     
    
    2507 2468
     
    
    2469
    +    if ( *pchar_code >= 0xFFFFFFFFUL )
    
    2470
    +      return 0;
    
    2471
    +
    
    2508 2472
         /* no need to search */
    
    2509 2473
         if ( cmap12->valid && cmap12->cur_charcode == *pchar_code )
    
    2510 2474
         {
    
    ... ... @@ -2688,9 +2652,6 @@
    2688 2652
         FT_UInt   gindex;
    
    2689 2653
     
    
    2690 2654
     
    
    2691
    -    if ( cmap->cur_charcode >= 0xFFFFFFFFUL )
    
    2692
    -      goto Fail;
    
    2693
    -
    
    2694 2655
         char_code = cmap->cur_charcode + 1;
    
    2695 2656
     
    
    2696 2657
         for ( n = cmap->cur_group; n < cmap->num_groups; n++ )
    
    ... ... @@ -2718,7 +2679,6 @@
    2718 2679
           }
    
    2719 2680
         }
    
    2720 2681
     
    
    2721
    -  Fail:
    
    2722 2682
         cmap->valid = 0;
    
    2723 2683
       }
    
    2724 2684
     
    
    ... ... @@ -2731,7 +2691,7 @@
    2731 2691
         FT_UInt    gindex     = 0;
    
    2732 2692
         FT_Byte*   p          = cmap->data + 12;
    
    2733 2693
         FT_UInt32  num_groups = TT_PEEK_ULONG( p );
    
    2734
    -    FT_UInt32  char_code  = *pchar_code;
    
    2694
    +    FT_UInt32  char_code  = *pchar_code + next;
    
    2735 2695
         FT_UInt32  start, end;
    
    2736 2696
         FT_UInt32  max, min, mid;
    
    2737 2697
     
    
    ... ... @@ -2739,23 +2699,11 @@
    2739 2699
         if ( !num_groups )
    
    2740 2700
           return 0;
    
    2741 2701
     
    
    2742
    -    /* make compiler happy */
    
    2743
    -    mid = num_groups;
    
    2744
    -    end = 0xFFFFFFFFUL;
    
    2745
    -
    
    2746
    -    if ( next )
    
    2747
    -    {
    
    2748
    -      if ( char_code >= 0xFFFFFFFFUL )
    
    2749
    -        return 0;
    
    2750
    -
    
    2751
    -      char_code++;
    
    2752
    -    }
    
    2753
    -
    
    2754 2702
         min = 0;
    
    2755 2703
         max = num_groups;
    
    2756 2704
     
    
    2757 2705
         /* binary search */
    
    2758
    -    while ( min < max )
    
    2706
    +    do
    
    2759 2707
         {
    
    2760 2708
           mid = ( min + max ) >> 1;
    
    2761 2709
           p   = cmap->data + 16 + 12 * mid;
    
    ... ... @@ -2774,6 +2722,7 @@
    2774 2722
             break;
    
    2775 2723
           }
    
    2776 2724
         }
    
    2725
    +    while ( min < max );
    
    2777 2726
     
    
    2778 2727
         if ( next )
    
    2779 2728
         {
    
    ... ... @@ -2784,12 +2733,8 @@
    2784 2733
           /* if `char_code' is not in any group, then `mid' is */
    
    2785 2734
           /* the group nearest to `char_code'                  */
    
    2786 2735
     
    
    2787
    -      if ( char_code > end )
    
    2788
    -      {
    
    2789
    -        mid++;
    
    2790
    -        if ( mid == num_groups )
    
    2791
    -          return 0;
    
    2792
    -      }
    
    2736
    +      if ( char_code > end && ++mid == num_groups )
    
    2737
    +        return 0;
    
    2793 2738
     
    
    2794 2739
           cmap13->valid        = 1;
    
    2795 2740
           cmap13->cur_charcode = char_code;
    
    ... ... @@ -2831,6 +2776,9 @@
    2831 2776
         FT_UInt    gindex;
    
    2832 2777
     
    
    2833 2778
     
    
    2779
    +    if ( *pchar_code >= 0xFFFFFFFFUL )
    
    2780
    +      return 0;
    
    2781
    +
    
    2834 2782
         /* no need to search */
    
    2835 2783
         if ( cmap13->valid && cmap13->cur_charcode == *pchar_code )
    
    2836 2784
         {
    


  • reply via email to

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