[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.
This commit is contained in:
parent
8ed6d97446
commit
7ad9d57c3b
@ -249,6 +249,7 @@ FT_BEGIN_HEADER
|
||||
/* structure type used to model object fields */
|
||||
typedef struct T1_FieldRec_
|
||||
{
|
||||
FT_UInt len; /* field identifier length */
|
||||
const char* ident; /* field identifier */
|
||||
T1_FieldLocation location;
|
||||
T1_FieldType type; /* type of field */
|
||||
@ -273,6 +274,7 @@ FT_BEGIN_HEADER
|
||||
|
||||
#define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname, _dict ) \
|
||||
{ \
|
||||
sizeof ( _ident ) - 1, \
|
||||
_ident, T1CODE, _type, \
|
||||
0, \
|
||||
FT_FIELD_OFFSET( _fname ), \
|
||||
@ -283,6 +285,7 @@ FT_BEGIN_HEADER
|
||||
|
||||
#define T1_NEW_CALLBACK_FIELD( _ident, _reader, _dict ) \
|
||||
{ \
|
||||
sizeof ( _ident ) - 1, \
|
||||
_ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
|
||||
(T1_Field_ParseFunc)_reader, \
|
||||
0, 0, \
|
||||
@ -292,6 +295,7 @@ FT_BEGIN_HEADER
|
||||
|
||||
#define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max, _dict ) \
|
||||
{ \
|
||||
sizeof ( _ident ) - 1, \
|
||||
_ident, T1CODE, _type, \
|
||||
0, \
|
||||
FT_FIELD_OFFSET( _fname ), \
|
||||
@ -303,6 +307,7 @@ FT_BEGIN_HEADER
|
||||
|
||||
#define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max, _dict ) \
|
||||
{ \
|
||||
sizeof ( _ident ) - 1, \
|
||||
_ident, T1CODE, _type, \
|
||||
0, \
|
||||
FT_FIELD_OFFSET( _fname ), \
|
||||
|
@ -478,26 +478,16 @@
|
||||
if ( !name )
|
||||
break;
|
||||
|
||||
if ( cur[0] == name[0] &&
|
||||
len == ft_strlen( (const char*)name ) )
|
||||
if ( keyword->len == len &&
|
||||
ft_memcmp( cur, name, len ) == 0 )
|
||||
{
|
||||
FT_UInt n;
|
||||
|
||||
|
||||
for ( n = 1; n < len; n++ )
|
||||
if ( cur[n] != name[n] )
|
||||
break;
|
||||
|
||||
if ( n >= len )
|
||||
{
|
||||
/* we found it - run the parsing callback */
|
||||
parser->root.error = cid_load_keyword( face,
|
||||
loader,
|
||||
keyword );
|
||||
if ( parser->root.error )
|
||||
return parser->root.error;
|
||||
break;
|
||||
}
|
||||
/* we found it - run the parsing callback */
|
||||
parser->root.error = cid_load_keyword( face,
|
||||
loader,
|
||||
keyword );
|
||||
if ( parser->root.error )
|
||||
return parser->root.error;
|
||||
break;
|
||||
}
|
||||
keyword++;
|
||||
}
|
||||
|
@ -2401,9 +2401,8 @@
|
||||
if ( !name )
|
||||
break;
|
||||
|
||||
if ( cur[0] == name[0] &&
|
||||
len == ft_strlen( (const char *)name ) &&
|
||||
ft_memcmp( cur, name, len ) == 0 )
|
||||
if ( keyword->len == len &&
|
||||
ft_memcmp( cur, name, len ) == 0 )
|
||||
{
|
||||
/* We found it -- run the parsing callback! */
|
||||
/* We record every instance of every field */
|
||||
|
@ -1288,9 +1288,8 @@
|
||||
if ( !name )
|
||||
continue;
|
||||
|
||||
if ( cur[0] == name[0] &&
|
||||
len == ft_strlen( (const char *)name ) &&
|
||||
ft_memcmp( cur, name, len ) == 0 )
|
||||
if ( keyword->len == len &&
|
||||
ft_memcmp( cur, name, len ) == 0 )
|
||||
{
|
||||
/* we found it -- run the parsing callback! */
|
||||
parser->root.error = t42_load_keyword( face,
|
||||
|
Loading…
Reference in New Issue
Block a user