improve performance of the truetype name table parsing

This commit is contained in:
Eliot Jones
2019-12-25 10:52:00 +00:00
parent 815705494a
commit a4805ce97d
3 changed files with 22 additions and 27 deletions

View File

@@ -4,26 +4,24 @@
{ {
public TrueTypePlatformIdentifier PlatformId { get; } public TrueTypePlatformIdentifier PlatformId { get; }
public int PlatformEncodingId { get; } public ushort PlatformEncodingId { get; }
public int LanguageId { get; } public ushort LanguageId { get; }
public int NameId { get; }
public int Length { get; }
public int Offset { get; }
public ushort NameId { get; }
public string Value { get; } public string Value { get; }
public TrueTypeNameRecord(TrueTypePlatformIdentifier platformId, int platformEncodingId, int languageId, int nameId, int length, int offset, string value) public TrueTypeNameRecord(TrueTypePlatformIdentifier platformId,
ushort platformEncodingId,
ushort languageId,
ushort nameId,
string value)
{ {
PlatformId = platformId; PlatformId = platformId;
PlatformEncodingId = platformEncodingId; PlatformEncodingId = platformEncodingId;
LanguageId = languageId; LanguageId = languageId;
NameId = nameId; NameId = nameId;
Length = length;
Offset = offset;
Value = value; Value = value;
} }

View File

@@ -111,17 +111,20 @@
{ {
public TrueTypePlatformIdentifier PlatformId { get; } public TrueTypePlatformIdentifier PlatformId { get; }
public int PlatformEncodingId { get; } public ushort PlatformEncodingId { get; }
private int LanguageId { get; } private ushort LanguageId { get; }
private int NameId { get; } private ushort NameId { get; }
public int Length { get; } public ushort Length { get; }
public int Offset { get; } public ushort Offset { get; }
private NameRecordBuilder(int platformId, int platformEncodingId, int languageId, int nameId, int length, int offset) private NameRecordBuilder(ushort platformId, ushort platformEncodingId, ushort languageId,
ushort nameId,
ushort length,
ushort offset)
{ {
PlatformId = (TrueTypePlatformIdentifier)platformId; PlatformId = (TrueTypePlatformIdentifier)platformId;
PlatformEncodingId = platformEncodingId; PlatformEncodingId = platformEncodingId;
@@ -134,7 +137,7 @@
public TrueTypeNameRecord ToNameRecord(string s) public TrueTypeNameRecord ToNameRecord(string s)
{ {
return new TrueTypeNameRecord(PlatformId, PlatformEncodingId, return new TrueTypeNameRecord(PlatformId, PlatformEncodingId,
LanguageId, NameId, Length, Offset, s); LanguageId, NameId, s);
} }
public static NameRecordBuilder Read(TrueTypeDataBytes data) public static NameRecordBuilder Read(TrueTypeDataBytes data)

View File

@@ -41,16 +41,10 @@
private void ReadBuffered(byte[] buffer, int length) private void ReadBuffered(byte[] buffer, int length)
{ {
var numberRead = 0; var read = inputBytes.Read(buffer, length);
while (numberRead < length) if (read < length)
{ {
if (!inputBytes.MoveNext()) throw new EndOfStreamException($"Could not read a buffer of {length} bytes.");
{
throw new EndOfStreamException($"Could not read a buffer of {length} bytes.");
}
buffer[numberRead] = inputBytes.CurrentByte;
numberRead++;
} }
} }