@@ -200,6 +200,10 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
200
200
bool _didExceedMaxLines ;
201
201
TabStops _tabStops = new TabStops ( ) ;
202
202
203
+ static float [ ] _advancesBuffer ;
204
+ static float [ ] _positionsBuffer ;
205
+ static Range < int > [ ] _wordsBuffer ;
206
+
203
207
// private float _characterWidth;
204
208
205
209
float _width ;
@@ -296,10 +300,10 @@ public void layout(ParagraphConstraints constraints) {
296
300
if ( maxWordCount == 0 ) {
297
301
return ;
298
302
}
299
- Range < int > [ ] words = new Range < int > [ maxWordCount ] ;
300
-
301
- float [ ] positions = null ;
302
- float [ ] advances = null ;
303
+
304
+ if ( _wordsBuffer == null || _wordsBuffer . Length < maxWordCount ) {
305
+ _wordsBuffer = new Range < int > [ maxWordCount ] ;
306
+ }
303
307
304
308
// Iterate through line ranges
305
309
for ( int lineNumber = 0 ; lineNumber < lineLimit ; ++ lineNumber ) {
@@ -316,7 +320,7 @@ public void layout(ParagraphConstraints constraints) {
316
320
// This is still not taken care of in the flutter engine.
317
321
! ( this . _paragraphStyle . ellipsized ( ) && this . _paragraphStyle . maxLines == null ) ;
318
322
319
- int wordCount = this . _findWords ( lineRange . start , lineRange . end , words ) ;
323
+ int wordCount = this . _findWords ( lineRange . start , lineRange . end , _wordsBuffer ) ;
320
324
float wordGapWidth = ! ( justifyLine && wordCount > 1 )
321
325
? 0
322
326
: ( this . _width - this . _lineWidths [ lineNumber ] ) / ( wordCount - 1 ) ;
@@ -334,12 +338,12 @@ public void layout(ParagraphConstraints constraints) {
334
338
// Allocate the advances and positions to store the layout result
335
339
// TODO: find a way to compute the maxTextCount for the entire paragraph, so that this allocation
336
340
// happens only once
337
- if ( advances == null || advances . Length < maxTextCount ) {
338
- advances = new float [ maxTextCount ] ;
341
+ if ( _advancesBuffer == null || _advancesBuffer . Length < maxTextCount ) {
342
+ _advancesBuffer = new float [ maxTextCount ] ;
339
343
}
340
344
341
- if ( positions == null || positions . Length < maxTextCount ) {
342
- positions = new float [ maxTextCount ] ;
345
+ if ( _positionsBuffer == null || _positionsBuffer . Length < maxTextCount ) {
346
+ _positionsBuffer = new float [ maxTextCount ] ;
343
347
}
344
348
345
349
// Keep of the position in glyphPositions before evaluating this line
@@ -393,24 +397,24 @@ public void layout(ParagraphConstraints constraints) {
393
397
}
394
398
395
399
float advance = Layout . doLayout ( runXOffset , text , textStart , textCount , style ,
396
- advances , positions , this . _tabStops , out var bounds ) ;
400
+ _advancesBuffer , _positionsBuffer , this . _tabStops , out var bounds ) ;
397
401
398
402
builder . allocRunPos ( style , text , textStart , textCount ) ;
399
403
// bounds relative to first character
400
- bounds . x -= positions [ 0 ] ;
404
+ bounds . x -= _positionsBuffer [ 0 ] ;
401
405
builder . setBounds ( bounds ) ;
402
406
403
407
// Update the max width of the words
404
408
// Fill in the glyph positions, and the positions of the text blob builder
405
409
float wordStartPosition = float . NaN ;
406
410
for ( int glyphIndex = 0 ; glyphIndex < textCount ; ++ glyphIndex ) {
407
- float glyphXOffset = positions [ glyphIndex ] + justifyXOffset ;
408
- float glyphAdvance = advances [ glyphIndex ] ;
411
+ float glyphXOffset = _positionsBuffer [ glyphIndex ] + justifyXOffset ;
412
+ float glyphAdvance = _advancesBuffer [ glyphIndex ] ;
409
413
builder . setPosition ( glyphIndex , glyphXOffset ) ;
410
414
glyphPositions [ pGlyphPositions ++ ] = new GlyphPosition ( runXOffset + glyphXOffset ,
411
415
glyphAdvance , new Range < int > ( textStart + glyphIndex , textStart + glyphIndex + 1 ) ) ;
412
416
if ( wordIndex < wordCount ) {
413
- Range < int > word = words [ wordIndex ] ;
417
+ Range < int > word = _wordsBuffer [ wordIndex ] ;
414
418
// Run into the start of current word, record the start position of this word
415
419
if ( word . start == start + glyphIndex ) {
416
420
wordStartPosition = runXOffset + glyphXOffset ;
0 commit comments