@@ -189,7 +189,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
189
189
List < LineRange > _lineRanges = new List < LineRange > ( ) ;
190
190
List < float > _lineWidths = new List < float > ( ) ;
191
191
List < float > _lineBaseLines = new List < float > ( ) ;
192
- List < GlyphLine > _glyphLines = new List < GlyphLine > ( ) ;
192
+ GlyphLine [ ] _glyphLines ;
193
193
float _maxIntrinsicWidth ;
194
194
float _minIntrinsicWidth ;
195
195
float _alphabeticBaseline ;
@@ -272,9 +272,9 @@ public void layout(ParagraphConstraints constraints) {
272
272
this . _lineHeights . Clear ( ) ;
273
273
this . _lineBaseLines . Clear ( ) ;
274
274
this . _codeUnitRuns . Clear ( ) ;
275
- this . _glyphLines . Clear ( ) ;
276
275
277
276
this . _computeLineBreak ( ) ;
277
+ this . _glyphLines = new GlyphLine [ this . _lineRanges . Count ] ;
278
278
int styleMaxLines = this . _paragraphStyle . maxLines ?? int . MaxValue ;
279
279
this . _didExceedMaxLines = this . _lineRanges . Count > styleMaxLines ;
280
280
@@ -296,7 +296,6 @@ public void layout(ParagraphConstraints constraints) {
296
296
297
297
// Compute max(NumberOfWords(line) for line in lines), to determine the size of word buffers
298
298
int maxWordCount = this . _computeMaxWordCount ( ) ;
299
- // Nothing to layout, if no visible character at all
300
299
301
300
if ( _wordsBuffer == null || _wordsBuffer . Length < maxWordCount ) {
302
301
_wordsBuffer = new Range < int > [ maxWordCount < 4 ? 4 : maxWordCount ] ;
@@ -516,8 +515,8 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
516
515
int nextLineStart = lineNumber < this . _lineRanges . Count - 1
517
516
? this . _lineRanges [ lineNumber + 1 ] . start
518
517
: this . _text . Length ;
519
- this . _glyphLines . Add (
520
- new GlyphLine ( glyphPositions , glyphPositionLineStart , count , nextLineStart - lineStart ) ) ;
518
+ this . _glyphLines [ lineNumber ] =
519
+ new GlyphLine ( glyphPositions , glyphPositionLineStart , count , nextLineStart - lineStart ) ;
521
520
for ( int i = 0 ; i < lineStyleRunCount ; i ++ ) {
522
521
var paintRecord = this . _paintRecords [ this . _paintRecords . Count - 1 - i ] ;
523
522
paintRecord . shift ( lineXOffset , yOffset ) ;
@@ -684,7 +683,10 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
684
683
685
684
GlyphLine glyphLine = this . _glyphLines [ yIndex ] ;
686
685
if ( glyphLine . count == 0 ) {
687
- int lineStartIndex = this . _glyphLines . Where ( ( g , i ) => i < yIndex ) . Sum ( ( gl ) => gl . totalCountUnits ) ;
686
+ int lineStartIndex = 0 ;
687
+ for ( int i = 0 ; i < yIndex ; i ++ ) {
688
+ lineStartIndex += this . _glyphLines [ i ] . totalCountUnits ;
689
+ }
688
690
return new PositionWithAffinity ( lineStartIndex , TextAffinity . downstream ) ;
689
691
}
690
692
0 commit comments