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

Commit 25e63a0

Browse files
author
Yuncong Zhang
committed
Make this._lineBaseLines and this._lineHeights array.
1 parent 7b9a1c8 commit 25e63a0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Runtime/ui/txt/paragraph.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
188188
ParagraphStyle _paragraphStyle;
189189
List<LineRange> _lineRanges = new List<LineRange>();
190190
List<float> _lineWidths = new List<float>();
191-
List<float> _lineBaseLines = new List<float>();
191+
float[] _lineBaseLines;
192192
GlyphLine[] _glyphLines;
193193
float _maxIntrinsicWidth;
194194
float _minIntrinsicWidth;
195195
float _alphabeticBaseline;
196196
float _ideographicBaseline;
197-
List<float> _lineHeights = new List<float>();
197+
float[] _lineHeights;
198198
List<PaintRecord> _paintRecords = new List<PaintRecord>();
199199
List<CodeUnitRun> _codeUnitRuns = new List<CodeUnitRun>();
200200
bool _didExceedMaxLines;
@@ -211,7 +211,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
211211
const float kFloatDecorationSpacing = 3.0f;
212212

213213
public float height {
214-
get { return this._lineHeights.Count == 0 ? 0 : this._lineHeights.last(); }
214+
get { return this._lineHeights?.last() ?? 0; }
215215
}
216216

217217
public float minIntrinsicWidth {
@@ -269,12 +269,12 @@ public void layout(ParagraphConstraints constraints) {
269269
this._needsLayout = false;
270270
this._width = Mathf.Floor(constraints.width);
271271
this._paintRecords.Clear();
272-
this._lineHeights.Clear();
273-
this._lineBaseLines.Clear();
274272
this._codeUnitRuns.Clear();
275273

276274
this._computeLineBreak();
277275
this._glyphLines = new GlyphLine[this._lineRanges.Count];
276+
this._lineBaseLines = new float[this._lineRanges.Count];
277+
this._lineHeights = new float[this._lineRanges.Count];
278278
int styleMaxLines = this._paragraphStyle.maxLines ?? int.MaxValue;
279279
this._didExceedMaxLines = this._lineRanges.Count > styleMaxLines;
280280

@@ -498,9 +498,9 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
498498
updateLineMetrics(metrics, this._paragraphStyle.lineHeight ?? TextStyle.kDefaultHeight);
499499
}
500500

501-
this._lineHeights.Add((this._lineHeights.Count == 0 ? 0 : this._lineHeights.last())
501+
this._lineHeights[lineNumber] = ((lineNumber == 0 ? 0 : this._lineHeights[lineNumber - 1])
502502
+ Mathf.Round(maxLineSpacing + maxDescent));
503-
this._lineBaseLines.Add(this._lineHeights.last() - maxDescent);
503+
this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
504504
yOffset += Mathf.Round(maxLineSpacing + preMaxDescent);
505505
preMaxDescent = maxDescent;
506506
float lineXOffset = this.getLineXOffset(runXOffset);
@@ -670,12 +670,12 @@ public List<TextBox> getRectsForRange(int start, int end) {
670670
}
671671

672672
internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
673-
if (this._lineHeights.Count == 0) {
673+
if (this._lineHeights == null) {
674674
return new PositionWithAffinity(0, TextAffinity.downstream);
675675
}
676676

677677
int yIndex;
678-
for (yIndex = 0; yIndex < this._lineHeights.Count - 1; ++yIndex) {
678+
for (yIndex = 0; yIndex < this._lineHeights.Length - 1; ++yIndex) {
679679
if (dy < this._lineHeights[yIndex]) {
680680
break;
681681
}
@@ -758,7 +758,7 @@ internal Range<int> getWordBoundary(int offset) {
758758
}
759759

760760
public int getLineCount() {
761-
return this._lineHeights.Count;
761+
return this._lineHeights?.Length ?? 0;
762762
}
763763

764764
void _computeLineBreak() {

0 commit comments

Comments
 (0)