Skip to content

Commit

Permalink
Replace ArrayList with List<GlyphRun> in PtsHost for performance/code…
Browse files Browse the repository at this point in the history
… quality (#9870)

* Reaplce ArrayList with List<GlyphRun> for performance

* Use pattern-matching in AddGlyphRunRecursive
  • Loading branch information
h3xds1nz authored Oct 19, 2024
1 parent bc5e56c commit b340d5c
Showing 1 changed file with 7 additions and 12 deletions.
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

0 comments on commit b340d5c

Please sign in to comment.