Skip to content
New issue

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

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

Already on GitHub? # to your account

Replace ArrayList with List<GlyphRun> in PtsHost for performance/code quality #9870

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ internal int GetEllipsesLength()
/// <param name="dcpEnd">
/// End dcp of range.
/// </param>
internal void GetGlyphRuns(System.Collections.Generic.List<GlyphRun> glyphRuns, int dcpStart, int dcpEnd)
internal void GetGlyphRuns(List<GlyphRun> glyphRuns, int dcpStart, int dcpEnd)
{
// NOTE: Following logic is only temporary workaround for lack
// of appropriate API that should be exposed by TextLine.
Expand All @@ -691,7 +691,7 @@ internal void GetGlyphRuns(System.Collections.Generic.List<GlyphRun> glyphRuns,
// Copy glyph runs into separate array (for backward navigation).
// And count number of chracters in the glyph runs collection.
int cchGlyphRuns = 0;
ArrayList glyphRunsCollection = new ArrayList(4);
List<GlyphRun> glyphRunsCollection = new(4);

AddGlyphRunRecursive(drawing, glyphRunsCollection, ref cchGlyphRuns);

Expand All @@ -712,7 +712,7 @@ internal void GetGlyphRuns(System.Collections.Generic.List<GlyphRun> glyphRuns,
// Remove those glyph runs from our colleciton.
while (cchGlyphRuns > cchTextSpans)
{
GlyphRun glyphRun = (GlyphRun)glyphRunsCollection[0];
GlyphRun glyphRun = glyphRunsCollection[0];
cchGlyphRuns -= (glyphRun.Characters == null ? 0 : glyphRun.Characters.Count);
glyphRunsCollection.RemoveAt(0);
}
Expand All @@ -727,7 +727,7 @@ internal void GetGlyphRuns(System.Collections.Generic.List<GlyphRun> glyphRuns,
while (cchRunsInSpan < span.Length)
{
Invariant.Assert(runIndex < glyphRunsCollection.Count);
GlyphRun run = (GlyphRun)glyphRunsCollection[runIndex];
GlyphRun run = glyphRunsCollection[runIndex];
int characterCount = (run.Characters == null ? 0 : run.Characters.Count);
if ((dcp < curDcp + characterCount) && (dcp + cch > curDcp))
{
Expand Down Expand Up @@ -1072,13 +1072,9 @@ private TextCollapsingProperties GetCollapsingProps(double wrappingWidth, LinePr
/// <param name="cchGlyphRuns">
/// Character length of glyph run collection
/// </param>
private void AddGlyphRunRecursive(
Drawing drawing,
IList glyphRunsCollection,
ref int cchGlyphRuns)
private static void AddGlyphRunRecursive(Drawing drawing, List<GlyphRun> glyphRunsCollection, ref int cchGlyphRuns)
{
DrawingGroup group = drawing as DrawingGroup;
if (group != null)
if (drawing is DrawingGroup group)
{
foreach (Drawing child in group.Children)
{
Expand All @@ -1087,8 +1083,7 @@ private void AddGlyphRunRecursive(
}
else
{
GlyphRunDrawing glyphRunDrawing = drawing as GlyphRunDrawing;
if (glyphRunDrawing != null)
if (drawing is GlyphRunDrawing glyphRunDrawing)
{
// Add a glyph run
GlyphRun glyphRun = glyphRunDrawing.GlyphRun;
Expand Down