Replace boxing IList in HighlightChangedEventArgs and seal derived classes #9559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
Ranges
property on the internal classHighlightChangedEventArgs
was declared as anIList
, but was always backed by an instance ofReadOnlyList<TextSegment>
. Retrieving a list of text segments would thus always box an instance of theTextSegment
struct. I've changed this property to declare it as anIList<TextSegment>
.I also swapped an
ArrayList
with aList<int>
in FixedDocument.cs, which stored a list of page numbers.Finally, I marked all the five classes derived from
HighlightChangedEventArgs
as sealed. All fives of these classes were private, so there's no API surface change here.Customer Impact
Reduced memory usage/GC pressure.
Regression
No.
Testing
Local build and tests, sample application runs.
Risk
Low. The
Ranges
property is only read byDocumentSequenceTextContainer
,FixedDocument
andFlowDocument
. In all three locations, it's indexed into and the result was explicitly cast to aTextSegment
.Microsoft Reviewers: Open in CodeFlow