8000 Optimize FontSourceCollection creation from a filesystem directory, reduce allocs by h3xds1nz · Pull Request #9844 · dotnet/wpf · GitHub
[go: up one dir, main page]

Skip to content

Optimize FontSourceCollection creation from a filesystem directory, reduce allocs #9844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Post-merge conflicts fixes
  • Loading branch information
h3xds1nz committed Apr 9, 2025
commit ada2d0eb6800377ad08d44d5443c091c64cfcb81
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
Expand Down Expand Up @@ -81,7 +81,7 @@ private void SetFontSources()
{
List<IFontSource> fontSources;
if (_uri.IsFile)
{
{
if (_isFileSystemFolder)
{
if (_tryGetCompositeFontsOnly)
Expand All @@ -90,7 +90,7 @@ private void SetFontSources()
fontSources = new List<IFontSource>(files.Length);

foreach (string file in files)
fontSources.Add(new FontSource(new Uri(file, UriKind.Absolute), _isWindowsFonts, true));
fontSources.Add(new FontSource(new Uri(file, UriKind.Absolute), true));
}
else
{
Expand All @@ -99,15 +99,15 @@ private void SetFontSources()
foreach (string file in Util.EnumerateFontsInDirectory(_uri.LocalPath))
{
bool isComposite = Util.IsCompositeFont(file);
fontSources.Add(new FontSource(new Uri(file, UriKind.Absolute), _isWindowsFonts, isComposite));
fontSources.Add(new FontSource(new Uri(file, UriKind.Absolute), isComposite));
}
}
}
else
{
fontSources = new List<IFontSource>(1);
if (Util.IsSupportedFontExtension(Path.GetExtension(_uri.LocalPath.AsSpan()), out bool isComposite))
fontSources.Add(new FontSource(new Uri(_uri.LocalPath, UriKind.Absolute), _isWindowsFonts, isComposite));
fontSources.Add(new FontSource(new Uri(_uri.LocalPath, UriKind.Absolute), isComposite));
}
}
else
Expand Down Expand Up @@ -145,7 +145,7 @@ private void SetFontSources()
}
}


#region IEnumerable<FontSource> Members

IEnumerator<IFontSource> IEnumerable<IFontSource>.GetEnumerator()
Expand All @@ -164,8 +164,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
return _fontSources.GetEnumerator();
}

#endregion

#endregion

private Uri _uri;

Expand Down
0