Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 7b9a1c8

Browse files
author
Yuncong Zhang
committed
Make this._glyphLines array.
1 parent ed3209b commit 7b9a1c8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Runtime/ui/txt/paragraph.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
189189
List<LineRange> _lineRanges = new List<LineRange>();
190190
List<float> _lineWidths = new List<float>();
191191
List<float> _lineBaseLines = new List<float>();
192-
List<GlyphLine> _glyphLines = new List<GlyphLine>();
192+
GlyphLine[] _glyphLines;
193193
float _maxIntrinsicWidth;
194194
float _minIntrinsicWidth;
195195
float _alphabeticBaseline;
@@ -272,9 +272,9 @@ public void layout(ParagraphConstraints constraints) {
272272
this._lineHeights.Clear();
273273
this._lineBaseLines.Clear();
274274
this._codeUnitRuns.Clear();
275-
this._glyphLines.Clear();
276275

277276
this._computeLineBreak();
277+
this._glyphLines = new GlyphLine[this._lineRanges.Count];
278278
int styleMaxLines = this._paragraphStyle.maxLines ?? int.MaxValue;
279279
this._didExceedMaxLines = this._lineRanges.Count > styleMaxLines;
280280

@@ -296,7 +296,6 @@ public void layout(ParagraphConstraints constraints) {
296296

297297
// Compute max(NumberOfWords(line) for line in lines), to determine the size of word buffers
298298
int maxWordCount = this._computeMaxWordCount();
299-
// Nothing to layout, if no visible character at all
300299

301300
if (_wordsBuffer == null || _wordsBuffer.Length < maxWordCount) {
302301
_wordsBuffer = new Range<int>[maxWordCount < 4 ? 4 : maxWordCount];
@@ -516,8 +515,8 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
516515
int nextLineStart = lineNumber < this._lineRanges.Count - 1
517516
? this._lineRanges[lineNumber + 1].start
518517
: 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);
521520
for (int i = 0; i < lineStyleRunCount; i++) {
522521
var paintRecord = this._paintRecords[this._paintRecords.Count - 1 - i];
523522
paintRecord.shift(lineXOffset, yOffset);
@@ -684,7 +683,10 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
684683

685684
GlyphLine glyphLine = this._glyphLines[yIndex];
686685
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+
}
688690
return new PositionWithAffinity(lineStartIndex, TextAffinity.downstream);
689691
}
690692

0 commit comments

Comments
 (0)