diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-06-15 09:45:57 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2010-06-15 14:58:24 +0200 |
commit | 5ab1e41c5b7d5dbe8d1a0d31dfcde582c5b2f390 (patch) | |
tree | 1e9e009619b2e6b3db4d9d1def7d852830babe96 | |
parent | ce1f5b080dc944c05fbf16ee1b3669add709b427 (diff) |
Always allocate HB_Device structs dynamically.
These are often unnecessary and allocating them dynamically will save
5 bytes per instance.
Signed-off-by: Simon Hausmann <simon.hausmann@nokia.com>
Signed-off-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/harfbuzz-dump.c | 10 | ||||
-rw-r--r-- | src/harfbuzz-gdef-private.h | 2 | ||||
-rw-r--r-- | src/harfbuzz-gpos-private.h | 12 | ||||
-rw-r--r-- | src/harfbuzz-gpos.c | 24 | ||||
-rw-r--r-- | src/harfbuzz-open-private.h | 6 | ||||
-rw-r--r-- | src/harfbuzz-open.c | 36 |
6 files changed, 53 insertions, 37 deletions
diff --git a/src/harfbuzz-dump.c b/src/harfbuzz-dump.c index 918fd56..a1ef6b6 100644 --- a/src/harfbuzz-dump.c +++ b/src/harfbuzz-dump.c @@ -519,15 +519,15 @@ Dump_ValueRecord (HB_ValueRecord *ValueRecord, FILE *stream, int indent, HB_Type if (value_format & HB_GPOS_FORMAT_HAVE_Y_ADVANCE) DUMP_FINT (ValueRecord, XAdvance); if (value_format & HB_GPOS_FORMAT_HAVE_X_PLACEMENT_DEVICE) - RECURSE (Device, Device, &ValueRecord->XPlacementDevice); + RECURSE (Device, Device, &*ValueRecord->XPlacementDevice); if (value_format & HB_GPOS_FORMAT_HAVE_Y_PLACEMENT_DEVICE) - RECURSE (Device, Device, &ValueRecord->YPlacementDevice); + RECURSE (Device, Device, &*ValueRecord->YPlacementDevice); if (value_format & HB_GPOS_FORMAT_HAVE_X_ADVANCE_DEVICE) - RECURSE (Device, Device, &ValueRecord->XAdvanceDevice); + RECURSE (Device, Device, &*ValueRecord->XAdvanceDevice); if (value_format & HB_GPOS_FORMAT_HAVE_Y_ADVANCE_DEVICE) - RECURSE (Device, Device, &ValueRecord->YAdvanceDevice); - if (value_format & HB_GPOS_FORMAT_HAVE_X_ID_PLACEMENT) + RECURSE (Device, Device, &*ValueRecord->YAdvanceDevice); #ifdef HB_SUPPORT_MULTIPLE_MASTER + if (value_format & HB_GPOS_FORMAT_HAVE_X_ID_PLACEMENT) DUMP_FUINT (ValueRecord, XIdPlacement); if (value_format & HB_GPOS_FORMAT_HAVE_Y_ID_PLACEMENT) DUMP_FUINT (ValueRecord, YIdPlacement); diff --git a/src/harfbuzz-gdef-private.h b/src/harfbuzz-gdef-private.h index 3d1d4c2..0e9c03c 100644 --- a/src/harfbuzz-gdef-private.h +++ b/src/harfbuzz-gdef-private.h @@ -63,7 +63,7 @@ typedef struct HB_CaretValueFormat2_ HB_CaretValueFormat2; struct HB_CaretValueFormat3_ { HB_Short Coordinate; /* x or y value (in design units) */ - HB_Device Device; /* Device table for x or y value */ + HB_Device* Device; /* Device table for x or y value */ }; typedef struct HB_CaretValueFormat3_ HB_CaretValueFormat3; diff --git a/src/harfbuzz-gpos-private.h b/src/harfbuzz-gpos-private.h index 50fd252..6408b84 100644 --- a/src/harfbuzz-gpos-private.h +++ b/src/harfbuzz-gpos-private.h @@ -45,13 +45,13 @@ struct HB_ValueRecord_ advance */ HB_Short YAdvance; /* vertical adjustment for advance */ - HB_Device XPlacementDevice; /* device table for horizontal + HB_Device* XPlacementDevice; /* device table for horizontal placement */ - HB_Device YPlacementDevice; /* device table for vertical + HB_Device* YPlacementDevice; /* device table for vertical placement */ - HB_Device XAdvanceDevice; /* device table for horizontal + HB_Device* XAdvanceDevice; /* device table for horizontal advance */ - HB_Device YAdvanceDevice; /* device table for vertical + HB_Device* YAdvanceDevice; /* device table for vertical advance */ #ifdef HB_SUPPORT_MULTIPLE_MASTER HB_UShort XIdPlacement; /* horizontal placement metric ID */ @@ -104,8 +104,8 @@ struct HB_AnchorFormat3_ { HB_Short XCoordinate; /* horizontal value */ HB_Short YCoordinate; /* vertical value */ - HB_Device XDeviceTable; /* device table for X coordinate */ - HB_Device YDeviceTable; /* device table for Y coordinate */ + HB_Device* XDeviceTable; /* device table for X coordinate */ + HB_Device* YDeviceTable; /* device table for Y coordinate */ }; typedef struct HB_AnchorFormat3_ HB_AnchorFormat3; diff --git a/src/harfbuzz-gpos.c b/src/harfbuzz-gpos.c index a105ce0..61e42fd 100644 --- a/src/harfbuzz-gpos.c +++ b/src/harfbuzz-gpos.c @@ -282,9 +282,7 @@ static HB_Error Load_ValueRecord( HB_ValueRecord* vr, else { empty1: - vr->XPlacementDevice.StartSize = 0; - vr->XPlacementDevice.EndSize = 0; - vr->XPlacementDevice.DeltaValue = NULL; + vr->XPlacementDevice = 0; } if ( format & HB_GPOS_FORMAT_HAVE_Y_PLACEMENT_DEVICE ) @@ -313,9 +311,7 @@ static HB_Error Load_ValueRecord( HB_ValueRecord* vr, else { empty2: - vr->YPlacementDevice.StartSize = 0; - vr->YPlacementDevice.EndSize = 0; - vr->YPlacementDevice.DeltaValue = NULL; + vr->YPlacementDevice = 0; } if ( format & HB_GPOS_FORMAT_HAVE_X_ADVANCE_DEVICE ) @@ -344,9 +340,7 @@ static HB_Error Load_ValueRecord( HB_ValueRecord* vr, else { empty3: - vr->XAdvanceDevice.StartSize = 0; - vr->XAdvanceDevice.EndSize = 0; - vr->XAdvanceDevice.DeltaValue = NULL; + vr->XAdvanceDevice = 0; } if ( format & HB_GPOS_FORMAT_HAVE_Y_ADVANCE_DEVICE ) @@ -375,9 +369,7 @@ static HB_Error Load_ValueRecord( HB_ValueRecord* vr, else { empty4: - vr->YAdvanceDevice.StartSize = 0; - vr->YAdvanceDevice.EndSize = 0; - vr->YAdvanceDevice.DeltaValue = NULL; + vr->YAdvanceDevice = 0; } if ( format & HB_GPOS_FORMAT_HAVE_X_ID_PLACEMENT ) @@ -651,9 +643,7 @@ static HB_Error Load_Anchor( HB_Anchor* an, } else { - an->af.af3.XDeviceTable.StartSize = 0; - an->af.af3.XDeviceTable.EndSize = 0; - an->af.af3.XDeviceTable.DeltaValue = NULL; + an->af.af3.XDeviceTable = 0; } if ( ACCESS_Frame( 2L ) ) @@ -676,9 +666,7 @@ static HB_Error Load_Anchor( HB_Anchor* an, } else { - an->af.af3.YDeviceTable.StartSize = 0; - an->af.af3.YDeviceTable.EndSize = 0; - an->af.af3.YDeviceTable.DeltaValue = NULL; + an->af.af3.YDeviceTable = 0; } break; diff --git a/src/harfbuzz-open-private.h b/src/harfbuzz-open-private.h index 73dd383..1f7b353 100644 --- a/src/harfbuzz-open-private.h +++ b/src/harfbuzz-open-private.h @@ -69,7 +69,7 @@ _HB_OPEN_Load_EmptyOrClassDefinition( HB_ClassDefinition* cd, HB_UInt base_offset, HB_Stream input ); HB_INTERNAL HB_Error -_HB_OPEN_Load_Device( HB_Device* d, +_HB_OPEN_Load_Device( HB_Device** d, HB_Stream input ); HB_INTERNAL void _HB_OPEN_Free_ScriptList( HB_ScriptList* sl ); @@ -79,7 +79,7 @@ HB_INTERNAL void _HB_OPEN_Free_LookupList( HB_LookupList* ll, HB_INTERNAL void _HB_OPEN_Free_Coverage( HB_Coverage* c ); HB_INTERNAL void _HB_OPEN_Free_ClassDefinition( HB_ClassDefinition* cd ); -HB_INTERNAL void _HB_OPEN_Free_Device( HB_Device* d ); +HB_INTERNAL void _HB_OPEN_Free_Device( HB_Device** d ); @@ -93,7 +93,7 @@ _HB_OPEN_Get_Class( HB_ClassDefinition* cd, HB_UShort* klass, HB_UShort* index ); HB_INTERNAL HB_Error -_HB_OPEN_Get_Device( HB_Device* d, +_HB_OPEN_Get_Device( HB_Device** d, HB_UShort size, HB_Short* value ); diff --git a/src/harfbuzz-open.c b/src/harfbuzz-open.c index 0fe1e4d..4fc6ed1 100644 --- a/src/harfbuzz-open.c +++ b/src/harfbuzz-open.c @@ -1282,7 +1282,7 @@ _HB_OPEN_Get_Class( HB_ClassDefinition* cd, HB_INTERNAL HB_Error -_HB_OPEN_Load_Device( HB_Device* d, +_HB_OPEN_Load_Device( HB_Device** device, HB_Stream stream ) { HB_Error error; @@ -1295,6 +1295,14 @@ _HB_OPEN_Load_Device( HB_Device* d, if ( ACCESS_Frame( 6L ) ) return error; + if ( ALLOC( *device, sizeof(HB_Device)) ) + { + *device = 0; + return error; + } + + HB_Device* d = *device; + d->StartSize = GET_UShort(); d->EndSize = GET_UShort(); d->DeltaFormat = GET_UShort(); @@ -1318,11 +1326,17 @@ _HB_OPEN_Load_Device( HB_Device* d, ( 4 - d->DeltaFormat ) ) + 1; if ( ALLOC_ARRAY( d->DeltaValue, count, HB_UShort ) ) + { + FREE( *device ); + *device = 0; return error; + } if ( ACCESS_Frame( count * 2L ) ) { FREE( d->DeltaValue ); + FREE( *device ); + *device = 0; return error; } @@ -1338,9 +1352,13 @@ _HB_OPEN_Load_Device( HB_Device* d, HB_INTERNAL void -_HB_OPEN_Free_Device( HB_Device* d ) +_HB_OPEN_Free_Device( HB_Device** d ) { - FREE( d->DeltaValue ); + if ( *d ) + { + FREE( (*d)->DeltaValue ); + FREE( *d ); + } } @@ -1380,12 +1398,20 @@ _HB_OPEN_Free_Device( HB_Device* d ) mask = 0x00FF */ HB_INTERNAL HB_Error -_HB_OPEN_Get_Device( HB_Device* d, +_HB_OPEN_Get_Device( HB_Device** device, HB_UShort size, HB_Short* value ) { HB_UShort byte, bits, mask, f, s; + HB_Error error; + + if ( ALLOC( *device, sizeof(HB_Device)) ) + { + *device = 0; + return error; + } + HB_Device* d = *device; f = d->DeltaFormat; @@ -1408,6 +1434,8 @@ _HB_OPEN_Get_Device( HB_Device* d, else { *value = 0; + FREE( *device ); + *device = 0; return HB_Err_Not_Covered; } } |