Improve text subtree advance calculation caching

This commit is contained in:
Mikael Sand
2019-02-10 02:52:15 +02:00
parent 66241b7a25
commit e69d2320b2
6 changed files with 33 additions and 4 deletions
@@ -108,6 +108,9 @@ class TSpanView extends TextView {
}
double getSubtreeTextChunksTotalAdvance(Paint paint) {
if (!Double.isNaN(cachedAdvance)) {
return cachedAdvance;
}
double advance = 0;
if (mContent == null) {
@@ -118,6 +121,7 @@ class TSpanView extends TextView {
advance += text.getSubtreeTextChunksTotalAdvance(paint);
}
}
cachedAdvance = advance;
return advance;
}
@@ -125,6 +129,7 @@ class TSpanView extends TextView {
final int length = line.length();
if (length == 0) {
cachedAdvance = 0;
return advance;
}
@@ -149,7 +154,8 @@ class TSpanView extends TextView {
paint.setLetterSpacing((float)(letterSpacing / (font.fontSize * mScale)));
}
return paint.measureText(line);
cachedAdvance = paint.measureText(line);
return cachedAdvance;
}
@SuppressWarnings("ConstantConditions")
@@ -50,11 +50,15 @@ class TextView extends GroupView {
if (mPath == null) {
return;
}
cachedAdvance = Double.NaN;
super.invalidate();
clearChildCache();
}
void clearCache() {
cachedAdvance = Double.NaN;
super.clearCache();
}
@ReactProp(name = "textLength")
public void setTextLength(Dynamic length) {
mTextLength = SVGLength.from(length);
@@ -101,7 +101,7 @@ abstract public class VirtualView extends ReactViewGroup {
super.invalidate();
}
private void clearCache() {
void clearCache() {
canvasDiagonal = -1;
canvasHeight = -1;
canvasWidth = -1;