Skip to content

Commit e8455dc

Browse files
Use ReadOnlyCollection.Empty (#10013)
* Use ReadOnlyCollection.Empty * Replace EmptyList with ReadOnlyCollection.Empty * Revert TextBlock.cs changes
1 parent 70cbdce commit e8455dc

File tree

19 files changed

+37
-41
lines changed

19 files changed

+37
-41
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ internal IEnumerable<IManipulator> GetManipulatorsReadOnly()
209209
}
210210
else
211211
{
212-
return new ReadOnlyCollection<IManipulator>(new List<IManipulator>(2));
212+
return ReadOnlyCollection<IManipulator>.Empty;
213213
}
214214
}
215215

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParaClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ internal ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out boo
330330

331331
if (subtrackDetails.cParas == 0)
332332
{
333-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
333+
return ReadOnlyCollection<ParagraphResult>.Empty;
334334
}
335335

336336
// Get list of paragraphs

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ private ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out bool
569569

570570
if (trackDetails.cParas == 0)
571571
{
572-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
572+
return ReadOnlyCollection<ParagraphResult>.Empty;
573573
}
574574

575575
// Get list of paragraphs
@@ -595,7 +595,7 @@ private ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out bool
595595
// cBasicColumns == 0, means that subpage content is empty
596596
if (subpageDetails.u.complex.cBasicColumns == 0)
597597
{
598-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
598+
return ReadOnlyCollection<ParagraphResult>.Empty;
599599
}
600600

601601
// Retrieve description for each column.
@@ -609,7 +609,7 @@ private ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out bool
609609

610610
if (trackDetails.cParas == 0)
611611
{
612-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
612+
return ReadOnlyCollection<ParagraphResult>.Empty;
613613
}
614614

615615
// Get list of paragraphs
@@ -736,7 +736,7 @@ internal Geometry GetTightBoundingGeometryFromTextPositions(ReadOnlyCollection<C
736736
// Figure always has one column, so we can skip getting a column from the text position range
737737
Invariant.Assert(columns != null && columns.Count <= 1, "Columns collection is null.");
738738
Invariant.Assert(floatingElements != null, "Floating element collection is null.");
739-
ReadOnlyCollection<ParagraphResult> paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
739+
ReadOnlyCollection<ParagraphResult> paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : ReadOnlyCollection<ParagraphResult>.Empty;
740740

741741
if (paragraphs.Count > 0 || floatingElements.Count > 0)
742742
{

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ private ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out bool
578578

579579
if (trackDetails.cParas == 0)
580580
{
581-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
581+
return ReadOnlyCollection<ParagraphResult>.Empty;
582582
}
583583

584584
// Get list of paragraphs
@@ -604,7 +604,7 @@ private ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out bool
604604
// cBasicColumns == 0, means that subpage content is empty
605605
if (subpageDetails.u.complex.cBasicColumns == 0)
606606
{
607-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
607+
return ReadOnlyCollection<ParagraphResult>.Empty;
608608
}
609609

610610
// Retrieve description for each column.
@@ -618,7 +618,7 @@ private ReadOnlyCollection<ParagraphResult> GetChildrenParagraphResults(out bool
618618

619619
if (trackDetails.cParas == 0)
620620
{
621-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
621+
return ReadOnlyCollection<ParagraphResult>.Empty;
622622
}
623623

624624
// Get list of paragraphs
@@ -745,7 +745,7 @@ internal Geometry GetTightBoundingGeometryFromTextPositions(ReadOnlyCollection<C
745745
// Floater always has one column, so we can skip getting a column from the text position range
746746
Invariant.Assert(columns != null && columns.Count <= 1, "Columns collection is null.");
747747
Invariant.Assert(floatingElements != null, "Floating element collection is null.");
748-
ReadOnlyCollection<ParagraphResult> paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
748+
ReadOnlyCollection<ParagraphResult> paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : ReadOnlyCollection<ParagraphResult>.Empty;
749749

750750
if (paragraphs.Count > 0 || floatingElements.Count > 0)
751751
{

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ internal IEnumerator<IInputElement> HostedElementsCore
367367
else
368368
{
369369
// Return empty collection
370-
return new HostedElements(new ReadOnlyCollection<TextSegment>(new List<TextSegment>(0)));
370+
return new HostedElements(ReadOnlyCollection<TextSegment>.Empty);
371371
}
372372
}
373373
}
@@ -572,7 +572,7 @@ internal ReadOnlyCollection<ParagraphResult> GetParagraphResultsFromColumn(IntPt
572572

573573
if (trackDetails.cParas == 0)
574574
{
575-
return new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
575+
return ReadOnlyCollection<ParagraphResult>.Empty;
576576
}
577577

578578
PTS.FSPARADESCRIPTION[] arrayParaDesc;

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ ReadOnlyCollection<Rect> IContentHost.GetRectangles(ContentElement child)
124124
{
125125
return host.GetRectangles(child);
126126
}
127-
return new ReadOnlyCollection<Rect>(new List<Rect>(0));
127+
return ReadOnlyCollection<Rect>.Empty;
128128
}
129129

130130
/// <summary>

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParaClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ internal ReadOnlyCollection<LineResult> GetLineResults()
339339
#if TEXTPANELLAYOUTDEBUG
340340
TextPanelDebug.IncrementCounter("TextPara.GetLines", TextPanelDebug.Category.TextView);
341341
#endif
342-
ReadOnlyCollection<LineResult> lines = new ReadOnlyCollection<LineResult>(new List<LineResult>(0));
342+
ReadOnlyCollection<LineResult> lines = ReadOnlyCollection<LineResult>.Empty;
343343

344344
// Query paragraph details
345345
PTS.FSTEXTDETAILS textDetails;

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageTextView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ internal override ReadOnlyCollection<GlyphRun> GetGlyphRuns(ITextPointer start,
313313
}
314314
if (IsPageMissing)
315315
{
316-
return new ReadOnlyCollection<GlyphRun>(new List<GlyphRun>());
316+
return ReadOnlyCollection<GlyphRun>.Empty;
317317
}
318318
return _pageTextView.GetGlyphRuns(start, end);
319319
}
@@ -528,7 +528,7 @@ internal override ReadOnlyCollection<TextSegment> TextSegments
528528
{
529529
if (!IsValid || IsPageMissing)
530530
{
531-
return new ReadOnlyCollection<TextSegment>(new List<TextSegment>());
531+
return ReadOnlyCollection<TextSegment>.Empty;
532532
}
533533
return _pageTextView.TextSegments;
534534
}

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ internal override ReadOnlyCollection<TextSegment> TextSegments
588588
// Verify that layout information is valid. Cannot continue if not valid.
589589
if (!IsValid)
590590
{
591-
return new ReadOnlyCollection<TextSegment>(new List<TextSegment>());
591+
return ReadOnlyCollection<TextSegment>.Empty;
592592
}
593593
return this.TextSegmentsCore;
594594
}
@@ -3515,7 +3515,7 @@ private Rect GetRectangleFromContentEdge(ParagraphResult paragraphResult, ITextP
35153515
/// <summary>
35163516
/// Cached collection of ColumnResults.
35173517
/// </summary>
3518-
private static ReadOnlyCollection<ParagraphResult> _emptyParagraphCollection = new ReadOnlyCollection<ParagraphResult>(new List<ParagraphResult>(0));
3518+
private static ReadOnlyCollection<ParagraphResult> _emptyParagraphCollection = ReadOnlyCollection<ParagraphResult>.Empty;
35193519

35203520
/// <summary>
35213521
/// Cached collection of TextSegments.

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextViewBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ internal virtual ReadOnlyCollection<GlyphRun> GetGlyphRuns(ITextPointer start, I
109109
{
110110
throw new InvalidOperationException(SR.TextViewInvalidLayout);
111111
}
112-
return new ReadOnlyCollection<GlyphRun>(new List<GlyphRun>());
112+
return ReadOnlyCollection<GlyphRun>.Empty;
113113
}
114114

115115
/// <summary>

0 commit comments

Comments
 (0)