add capacity to glyph list dictionaries

This commit is contained in:
Eliot Jones
2023-05-21 19:13:14 +01:00
parent 976d8929a1
commit bb4c6f2f1e
2 changed files with 15 additions and 3 deletions

View File

@@ -43,7 +43,7 @@
{
nameToUnicode = namesToUnicode;
var unicodeToNameTemp = new Dictionary<string, string>();
var unicodeToNameTemp = new Dictionary<string, string>(namesToUnicode.Count);
foreach (var pair in namesToUnicode)
{

View File

@@ -18,19 +18,31 @@
throw new ArgumentException($"No embedded glyph list resource was found with the name {listName}.");
}
int? capacity = null;
// Prevent too much wasted memory capacity for Adobe GlyphList
if (string.Equals("glyphlist", listName, StringComparison.OrdinalIgnoreCase))
{
capacity = 4300;
}
return Read(resource);
return ReadInternal(resource, capacity);
}
}
public static GlyphList Read(Stream stream)
{
return ReadInternal(stream);
}
private static GlyphList ReadInternal(Stream stream, int? defaultDictionaryCapacity = 0)
{
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
var result = new Dictionary<string, string>();
var result = defaultDictionaryCapacity.HasValue ? new Dictionary<string, string>(defaultDictionaryCapacity.Value)
: new Dictionary<string, string>();
using (var reader = new StreamReader(stream))
{