ref: c2d283143a022632f04625fe194c72a1cfb7ac2b
parent: f998eaf9728b831d8447dbda4e3fba4b6f98cbfa
author: Alexei Podtelezhnikov <apodtele@gmail.com>
date: Sun Apr 25 19:33:15 EDT 2021
[bdf,pcf] Avoid some memory zeroing. * src/pcf/pcfread.c (pcf_read_TOC, pcf_get_properties, pcf_load_font): Tweak memory macros. * src/bdf/bdfdrivr.c (BDF_Face_Init): Ditto. * src/bdf/bdflib.c (_bdf_readstreami, bdf_create_property, _bdf_parse_glyphs, _bdf_parse_start): Ditto. (_bdf_add_property): Do not handle zero size.
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2021-04-25 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [bdf,pcf] Avoid some memory zeroing.
+
+ * src/pcf/pcfread.c (pcf_read_TOC, pcf_get_properties, pcf_load_font):
+ Tweak memory macros.
+ * src/bdf/bdfdrivr.c (BDF_Face_Init): Ditto.
+ * src/bdf/bdflib.c (_bdf_readstreami, bdf_create_property,
+ _bdf_parse_glyphs, _bdf_parse_start): Ditto.
+ (_bdf_add_property): Do not handle zero size.
+
2021-04-25 Issam E. Maghni <issam.e.maghni@mailbox.org>
* builds/meson/process_ftoption_h.py: Add LF at EOF.
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -442,7 +442,7 @@
bdfface->num_glyphs = (FT_Long)( font->glyphs_size + 1 );
bdfface->num_fixed_sizes = 1;
- if ( FT_NEW_ARRAY( bdfface->available_sizes, 1 ) )
+ if ( FT_NEW( bdfface->available_sizes ) )
goto Exit;
{
@@ -450,8 +450,6 @@
FT_Short resolution_x = 0, resolution_y = 0;
long value;
-
- FT_ZERO( bsize );
/* sanity checks */
if ( font->font_ascent > 0x7FFF || font->font_ascent < -0x7FFF )
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -538,7 +538,7 @@
/* initial size and allocation of the input buffer */
buf_size = 1024;
- if ( FT_NEW_ARRAY( buf, buf_size ) )
+ if ( FT_QALLOC( buf, buf_size ) )
goto Exit;
cb = callback;
@@ -599,7 +599,7 @@
}
new_size = buf_size * 2;
- if ( FT_RENEW_ARRAY( buf, buf_size, new_size ) )
+ if ( FT_QREALLOC( buf, buf_size, new_size ) )
goto Exit;
cursor = (ptrdiff_t)buf_size;
@@ -850,13 +850,12 @@
goto Exit;
p = font->user_props + font->nuser_props;
- FT_ZERO( p );
n = ft_strlen( name ) + 1;
if ( n > FT_ULONG_MAX )
return FT_THROW( Invalid_Argument );
- if ( FT_NEW_ARRAY( p->name, n ) )
+ if ( FT_QALLOC( p->name, n ) )
goto Exit;
FT_MEM_COPY( (char *)p->name, name, n );
@@ -1159,21 +1158,12 @@
/* Allocate another property if this is overflowing. */
if ( font->props_used == font->props_size )
{
- if ( font->props_size == 0 )
- {
- if ( FT_NEW_ARRAY( font->props, 1 ) )
- goto Exit;
- }
- else
- {
- if ( FT_RENEW_ARRAY( font->props,
- font->props_size,
- font->props_size + 1 ) )
- goto Exit;
- }
+ if ( FT_RENEW_ARRAY( font->props,
+ font->props_size,
+ font->props_size + 1 ) )
+ goto Exit;
fp = font->props + font->props_size;
- FT_ZERO( fp );
font->props_size++;
}
@@ -1438,7 +1428,7 @@
goto Exit;
}
- if ( FT_NEW_ARRAY( p->glyph_name, slen + 1 ) )
+ if ( FT_QALLOC( p->glyph_name, slen + 1 ) )
goto Exit;
FT_MEM_COPY( p->glyph_name, s, slen + 1 );
@@ -1735,7 +1725,7 @@
else
glyph->bytes = (unsigned short)bitmap_size;
- if ( FT_NEW_ARRAY( glyph->bitmap, glyph->bytes ) )
+ if ( FT_ALLOC( glyph->bitmap, glyph->bytes ) )
goto Exit;
p->row = 0;
@@ -2055,7 +2045,7 @@
/* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */
FT_FREE( p->font->name );
- if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) )
+ if ( FT_QALLOC( p->font->name, slen + 1 ) )
goto Exit;
FT_MEM_COPY( p->font->name, s, slen + 1 );
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -127,7 +127,7 @@
toc->count = FT_MIN( stream->size >> 4, 9 );
}
- if ( FT_NEW_ARRAY( face->toc.tables, toc->count ) )
+ if ( FT_QNEW_ARRAY( face->toc.tables, toc->count ) )
return error;
tables = face->toc.tables;
@@ -540,7 +540,7 @@
face->nprops = (int)nprops;
- if ( FT_NEW_ARRAY( props, nprops ) )
+ if ( FT_QNEW_ARRAY( props, nprops ) )
goto Bail;
for ( i = 0; i < nprops; i++ )
@@ -607,12 +607,11 @@
}
/* allocate one more byte so that we have a final null byte */
- if ( FT_NEW_ARRAY( strings, string_size + 1 ) )
+ if ( FT_QALLOC( strings, string_size + 1 ) ||
+ FT_STREAM_READ( strings, string_size ) )
goto Bail;
- error = FT_Stream_Read( stream, (FT_Byte*)strings, string_size );
- if ( error )
- goto Bail;
+ strings[string_size] = '\0';
if ( FT_NEW_ARRAY( properties, nprops ) )
goto Bail;
@@ -1532,7 +1531,7 @@
{
l += ft_strlen( foundry_prop->value.atom ) + 1;
- if ( FT_NEW_ARRAY( root->family_name, l ) )
+ if ( FT_QALLOC( root->family_name, l ) )
goto Exit;
ft_strcpy( root->family_name, foundry_prop->value.atom );
@@ -1541,7 +1540,7 @@
}
else
{
- if ( FT_NEW_ARRAY( root->family_name, l ) )
+ if ( FT_QALLOC( root->family_name, l ) )
goto Exit;
ft_strcpy( root->family_name, prop->value.atom );
@@ -1565,7 +1564,7 @@
root->num_glyphs = (FT_Long)face->nmetrics;
root->num_fixed_sizes = 1;
- if ( FT_NEW_ARRAY( root->available_sizes, 1 ) )
+ if ( FT_NEW( root->available_sizes ) )
goto Exit;
{
@@ -1572,8 +1571,6 @@
FT_Bitmap_Size* bsize = root->available_sizes;
FT_Short resolution_x = 0, resolution_y = 0;
-
- FT_ZERO( bsize );
/* for simplicity, we take absolute values of integer properties */