Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType
Commits:
-
8ed6d974
by Alexei Podtelezhnikov at 2023-09-09T15:13:55-04:00
* src/type1/t1afm.c (t1_get_index): Avoid `strlen` call.
Instead, we check the terminal zero.
-
7ad9d57c
by Alexei Podtelezhnikov at 2023-09-09T15:19:06-04:00
[type1, cid, type42] Streamline dictionary parsing.
When matching the keywords, we avoid calculating their lengths by
checking the stored values. This itself is a sufficient pre-check
before diving into `memcmp`. Therefore, we remove explicit check of
the first characters.
* include/freetype/internal/psaux.h (T1_FieldRec): Store length.
* src/cid/cidload.c (cid_parse_dict): Use `memcmp` and stored length.
* src/type1/t1load.c (parse_dict): Ditto.
* src/type42/t42parse.c (t42_parse_dict): Ditto.
5 changed files:
Changes:
include/freetype/internal/psaux.h
... |
... |
@@ -249,6 +249,7 @@ FT_BEGIN_HEADER |
249
|
249
|
/* structure type used to model object fields */
|
250
|
250
|
typedef struct T1_FieldRec_
|
251
|
251
|
{
|
|
252
|
+ FT_UInt len; /* field identifier length */
|
252
|
253
|
const char* ident; /* field identifier */
|
253
|
254
|
T1_FieldLocation location;
|
254
|
255
|
T1_FieldType type; /* type of field */
|
... |
... |
@@ -273,6 +274,7 @@ FT_BEGIN_HEADER |
273
|
274
|
|
274
|
275
|
#define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname, _dict ) \
|
275
|
276
|
{ \
|
|
277
|
+ sizeof ( _ident ) - 1, \
|
276
|
278
|
_ident, T1CODE, _type, \
|
277
|
279
|
0, \
|
278
|
280
|
FT_FIELD_OFFSET( _fname ), \
|
... |
... |
@@ -283,6 +285,7 @@ FT_BEGIN_HEADER |
283
|
285
|
|
284
|
286
|
#define T1_NEW_CALLBACK_FIELD( _ident, _reader, _dict ) \
|
285
|
287
|
{ \
|
|
288
|
+ sizeof ( _ident ) - 1, \
|
286
|
289
|
_ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
|
287
|
290
|
(T1_Field_ParseFunc)_reader, \
|
288
|
291
|
0, 0, \
|
... |
... |
@@ -292,6 +295,7 @@ FT_BEGIN_HEADER |
292
|
295
|
|
293
|
296
|
#define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max, _dict ) \
|
294
|
297
|
{ \
|
|
298
|
+ sizeof ( _ident ) - 1, \
|
295
|
299
|
_ident, T1CODE, _type, \
|
296
|
300
|
0, \
|
297
|
301
|
FT_FIELD_OFFSET( _fname ), \
|
... |
... |
@@ -303,6 +307,7 @@ FT_BEGIN_HEADER |
303
|
307
|
|
304
|
308
|
#define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max, _dict ) \
|
305
|
309
|
{ \
|
|
310
|
+ sizeof ( _ident ) - 1, \
|
306
|
311
|
_ident, T1CODE, _type, \
|
307
|
312
|
0, \
|
308
|
313
|
FT_FIELD_OFFSET( _fname ), \
|
src/cid/cidload.c
... |
... |
@@ -478,26 +478,16 @@ |
478
|
478
|
if ( !name )
|
479
|
479
|
break;
|
480
|
480
|
|
481
|
|
- if ( cur[0] == name[0] &&
|
482
|
|
- len == ft_strlen( (const char*)name ) )
|
|
481
|
+ if ( keyword->len == len &&
|
|
482
|
+ ft_memcmp( cur, name, len ) == 0 )
|
483
|
483
|
{
|
484
|
|
- FT_UInt n;
|
485
|
|
-
|
486
|
|
-
|
487
|
|
- for ( n = 1; n < len; n++ )
|
488
|
|
- if ( cur[n] != name[n] )
|
489
|
|
- break;
|
490
|
|
-
|
491
|
|
- if ( n >= len )
|
492
|
|
- {
|
493
|
|
- /* we found it - run the parsing callback */
|
494
|
|
- parser->root.error = cid_load_keyword( face,
|
495
|
|
- loader,
|
496
|
|
- keyword );
|
497
|
|
- if ( parser->root.error )
|
498
|
|
- return parser->root.error;
|
499
|
|
- break;
|
500
|
|
- }
|
|
484
|
+ /* we found it - run the parsing callback */
|
|
485
|
+ parser->root.error = cid_load_keyword( face,
|
|
486
|
+ loader,
|
|
487
|
+ keyword );
|
|
488
|
+ if ( parser->root.error )
|
|
489
|
+ return parser->root.error;
|
|
490
|
+ break;
|
501
|
491
|
}
|
502
|
492
|
keyword++;
|
503
|
493
|
}
|
src/type1/t1afm.c
... |
... |
@@ -69,8 +69,8 @@ |
69
|
69
|
|
70
|
70
|
|
71
|
71
|
if ( gname && gname[0] == name[0] &&
|
72
|
|
- ft_strlen( gname ) == len &&
|
73
|
|
- ft_strncmp( gname, name, len ) == 0 )
|
|
72
|
+ ft_strncmp( gname, name, len ) == 0 &&
|
|
73
|
+ gname[len] == 0 )
|
74
|
74
|
return n;
|
75
|
75
|
}
|
76
|
76
|
|
src/type1/t1load.c
... |
... |
@@ -2401,9 +2401,8 @@ |
2401
|
2401
|
if ( !name )
|
2402
|
2402
|
break;
|
2403
|
2403
|
|
2404
|
|
- if ( cur[0] == name[0] &&
|
2405
|
|
- len == ft_strlen( (const char *)name ) &&
|
2406
|
|
- ft_memcmp( cur, name, len ) == 0 )
|
|
2404
|
+ if ( keyword->len == len &&
|
|
2405
|
+ ft_memcmp( cur, name, len ) == 0 )
|
2407
|
2406
|
{
|
2408
|
2407
|
/* We found it -- run the parsing callback! */
|
2409
|
2408
|
/* We record every instance of every field */
|
src/type42/t42parse.c
... |
... |
@@ -1288,9 +1288,8 @@ |
1288
|
1288
|
if ( !name )
|
1289
|
1289
|
continue;
|
1290
|
1290
|
|
1291
|
|
- if ( cur[0] == name[0] &&
|
1292
|
|
- len == ft_strlen( (const char *)name ) &&
|
1293
|
|
- ft_memcmp( cur, name, len ) == 0 )
|
|
1291
|
+ if ( keyword->len == len &&
|
|
1292
|
+ ft_memcmp( cur, name, len ) == 0 )
|
1294
|
1293
|
{
|
1295
|
1294
|
/* we found it -- run the parsing callback! */
|
1296
|
1295
|
parser->root.error = t42_load_keyword( face,
|
|