@@ -21,6 +21,8 @@ public final class TerminalRow {
21
21
boolean mLineWrap ;
22
22
/** The style bits of each cell in the row. See {@link TextStyle}. */
23
23
final long [] mStyle ;
24
+ /** If this row might contain chars with width != 1, used for deactivating fast path */
25
+ boolean mHasNonOneWidthOrSurrogateChars ;
24
26
25
27
/** Construct a blank row (containing only whitespace, ' ') with a specified style. */
26
28
public TerminalRow (int columns , long style ) {
@@ -32,6 +34,7 @@ public TerminalRow(int columns, long style) {
32
34
33
35
/** NOTE: The sourceX2 is exclusive. */
34
36
public void copyInterval (TerminalRow line , int sourceX1 , int sourceX2 , int destinationX ) {
37
+ mHasNonOneWidthOrSurrogateChars |= line .mHasNonOneWidthOrSurrogateChars ;
35
38
final int x1 = line .findStartOfColumn (sourceX1 );
36
39
final int x2 = line .findStartOfColumn (sourceX2 );
37
40
boolean startingFromSecondHalfOfWideChar = (sourceX1 > 0 && line .wideDisplayCharacterStartingAt (sourceX1 - 1 ));
@@ -116,13 +119,25 @@ public void clear(long style) {
116
119
Arrays .fill (mText , ' ' );
117
120
Arrays .fill (mStyle , style );
118
121
mSpaceUsed = (short ) mColumns ;
122
+ mHasNonOneWidthOrSurrogateChars = false ;
119
123
}
120
124
121
125
// https://github.com/steven676/Android-Terminal-Emulator/commit/9a47042620bec87617f0b4f5d50568535668fe26
122
126
public void setChar (int columnToSet , int codePoint , long style ) {
123
127
mStyle [columnToSet ] = style ;
124
128
125
129
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
+
126
141
final boolean newIsCombining = newCodePointDisplayWidth <= 0 ;
127
142
128
143
boolean wasExtraColForWideChar = (columnToSet > 0 ) && wideDisplayCharacterStartingAt (columnToSet - 1 );
0 commit comments