Skip to content

Commit c8fb346

Browse files
committed
UnicodeTranscript: add fast path for getLine() on an entire FullUnicodeLine
getLine() is called frequently during screen drawing and other operations, usually with a request for the contents of an entire line. We have a fast path for this case with basic lines; something similar works for FullUnicodeLines, so let's do that too. Also, update the documentation to reflect the fact that the array returned from getLine() will not be null-terminated if the array size exactly matches the length of the requested text.
1 parent 09ead3a commit c8fb346

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

libraries/emulatorview/src/jackpal/androidterm/emulatorview/UnicodeTranscript.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,10 @@ public static int charWidth(char[] chars, int index) {
563563
* Get the contents of a line (or part of a line) of the transcript.
564564
*
565565
* The char[] array returned may be part of the internal representation
566-
* of the line -- make a copy first if you want to modify it. The last
567-
* character requested will be followed by a NUL; the contents of the rest
568-
* of the array could potentially be garbage.
566+
* of the line -- make a copy first if you want to modify it. The returned
567+
* array may be longer than the requested portion of the transcript; in
568+
* this case, the last character requested will be followed by a NUL, and
569+
* the contents of the rest of the array could potentially be garbage.
569570
*
570571
* @param row The row number to get (-mActiveTranscriptRows..mScreenRows-1)
571572
* @param x1 The first screen position that's wanted
@@ -602,6 +603,17 @@ public char[] getLine(int row, int x1, int x2) {
602603
// Figure out how long the array needs to be
603604
FullUnicodeLine line = (FullUnicodeLine) mLines[row];
604605
char[] rawLine = line.getLine();
606+
607+
if (x1 == 0 && x2 == columns) {
608+
/* We can return the raw line after ensuring it's NUL-terminated at
609+
* the appropriate place */
610+
int spaceUsed = line.getSpaceUsed();
611+
if (spaceUsed < rawLine.length) {
612+
rawLine[spaceUsed] = 0;
613+
}
614+
return rawLine;
615+
}
616+
605617
x1 = line.findStartOfColumn(x1);
606618
if (x2 < columns) {
607619
x2 = line.findStartOfColumn(x2);

0 commit comments

Comments
 (0)