Skip to content

Commit 3396c36

Browse files
committed
backend: improve terminal output speed
1 parent 247087c commit 3396c36

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/src/main/java/io/neoterm/backend/TerminalRow.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public final class TerminalRow {
2121
boolean mLineWrap;
2222
/** The style bits of each cell in the row. See {@link TextStyle}. */
2323
final long[] mStyle;
24+
/** If this row might contain chars with width != 1, used for deactivating fast path */
25+
boolean mHasNonOneWidthOrSurrogateChars;
2426

2527
/** Construct a blank row (containing only whitespace, ' ') with a specified style. */
2628
public TerminalRow(int columns, long style) {
@@ -32,6 +34,7 @@ public TerminalRow(int columns, long style) {
3234

3335
/** NOTE: The sourceX2 is exclusive. */
3436
public void copyInterval(TerminalRow line, int sourceX1, int sourceX2, int destinationX) {
37+
mHasNonOneWidthOrSurrogateChars |= line.mHasNonOneWidthOrSurrogateChars;
3538
final int x1 = line.findStartOfColumn(sourceX1);
3639
final int x2 = line.findStartOfColumn(sourceX2);
3740
boolean startingFromSecondHalfOfWideChar = (sourceX1 > 0 && line.wideDisplayCharacterStartingAt(sourceX1 - 1));
@@ -116,13 +119,25 @@ public void clear(long style) {
116119
Arrays.fill(mText, ' ');
117120
Arrays.fill(mStyle, style);
118121
mSpaceUsed = (short) mColumns;
122+
mHasNonOneWidthOrSurrogateChars = false;
119123
}
120124

121125
// https://github.com/steven676/Android-Terminal-Emulator/commit/9a47042620bec87617f0b4f5d50568535668fe26
122126
public void setChar(int columnToSet, int codePoint, long style) {
123127
mStyle[columnToSet] = style;
124128

125129
final int newCodePointDisplayWidth = WcWidth.width(codePoint);
130+
131+
// Fast path when we don't have any chars with width != 1
132+
if (!mHasNonOneWidthOrSurrogateChars) {
133+
if (codePoint >= Character.MIN_SUPPLEMENTARY_CODE_POINT || newCodePointDisplayWidth != 1) {
134+
mHasNonOneWidthOrSurrogateChars = true;
135+
} else {
136+
mText[columnToSet] = (char) codePoint;
137+
return;
138+
}
139+
}
140+
126141
final boolean newIsCombining = newCodePointDisplayWidth <= 0;
127142

128143
boolean wasExtraColForWideChar = (columnToSet > 0) && wideDisplayCharacterStartingAt(columnToSet - 1);

0 commit comments

Comments
 (0)