Skip to content

Commit 7a3f6fd

Browse files
Clean-up and optimize
1 parent f1fa51f commit 7a3f6fd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/SixLabors.Fonts/Tables/AdvancedTypographic/CoverageTable.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public static CoverageTable Load(BigEndianBinaryReader reader, long offset)
2828

2929
// Harfbuzz (Coverage.hh) treats this as an empty table and does not throw.
3030
// SofiaSans Condensed can trigger this. See https://github.com/SixLabors/Fonts/issues/470
31-
_ => new EmptyCoverageTable()
31+
_ => EmptyCoverageTable.Instance
3232
};
3333
}
3434

3535
public static CoverageTable[] LoadArray(BigEndianBinaryReader reader, long offset, ReadOnlySpan<ushort> coverageOffsets)
3636
{
37-
var tables = new CoverageTable[coverageOffsets.Length];
37+
CoverageTable[] tables = new CoverageTable[coverageOffsets.Length];
3838
for (int i = 0; i < tables.Length; i++)
3939
{
4040
tables[i] = Load(reader, offset + coverageOffsets[i]);
@@ -108,7 +108,7 @@ public static CoverageFormat2Table Load(BigEndianBinaryReader reader)
108108
// | RangeRecord | rangeRecords[rangeCount] | Array of glyph ranges — ordered by startGlyphID. |
109109
// +-------------+--------------------------+--------------------------------------------------+
110110
ushort rangeCount = reader.ReadUInt16();
111-
var records = new CoverageRangeRecord[rangeCount];
111+
CoverageRangeRecord[] records = new CoverageRangeRecord[rangeCount];
112112

113113
for (int i = 0; i < records.Length; i++)
114114
{
@@ -132,6 +132,12 @@ public static CoverageFormat2Table Load(BigEndianBinaryReader reader)
132132

133133
internal sealed class EmptyCoverageTable : CoverageTable
134134
{
135+
private EmptyCoverageTable()
136+
{
137+
}
138+
139+
public static EmptyCoverageTable Instance { get; } = new();
140+
135141
public override int CoverageIndexOf(ushort glyphId) => -1;
136142
}
137143
}

src/SixLabors.Fonts/Tables/AdvancedTypographic/GPos/AnchorTable.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace SixLabors.Fonts.Tables.AdvancedTypographic.GPos;
1111
[DebuggerDisplay("X: {XCoordinate}, Y: {YCoordinate}")]
1212
internal abstract class AnchorTable
1313
{
14-
private static readonly AnchorTable EmptyAnchorTable = new EmptyAnchor();
15-
1614
/// <summary>
1715
/// Initializes a new instance of the <see cref="AnchorTable"/> class.
1816
/// </summary>
@@ -55,7 +53,7 @@ public static AnchorTable Load(BigEndianBinaryReader reader, long offset)
5553

5654
// Harfbuzz (Anchor.hh) treats this as an empty table and does not throw..
5755
// NotoSans Regular can trigger this. See https://github.com/SixLabors/Fonts/issues/417
58-
_ => EmptyAnchorTable,
56+
_ => EmptyAnchorTable.Instance,
5957
};
6058
}
6159

@@ -185,13 +183,15 @@ public override AnchorXY GetAnchor(FontMetrics fontMetrics, GlyphShapingData dat
185183
=> new(this.XCoordinate, this.YCoordinate);
186184
}
187185

188-
internal sealed class EmptyAnchor : AnchorTable
186+
internal sealed class EmptyAnchorTable : AnchorTable
189187
{
190-
public EmptyAnchor()
188+
private EmptyAnchorTable()
191189
: base(0, 0)
192190
{
193191
}
194192

193+
public static EmptyAnchorTable Instance { get; } = new();
194+
195195
public override AnchorXY GetAnchor(
196196
FontMetrics fontMetrics,
197197
GlyphShapingData data,

0 commit comments

Comments
 (0)