performance
authorKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 22 Sep 2019 20:21:36 +0000 (15:21 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Sun, 22 Sep 2019 20:21:36 +0000 (15:21 -0500)
src/jexer/io/TimeoutInputStream.java
src/jexer/tterminal/ECMA48.java

index 3d8cdb0312494293b5e90bdeee39c5f21b32f659..70faff4eabaa0f932352b1886ea5651bfc424ac9 100644 (file)
@@ -244,7 +244,7 @@ public class TimeoutInputStream extends InputStream {
 
         if (timeoutMillis == 0) {
             // Block on the read().
-            return stream.read(b);
+            return stream.read(b, off, len);
         }
 
         int remaining = len;
index 1d3481169cc5300c5134c652e7745a962f42a2ec..d49229550f26bdae055c48297c5b66fa477cf486 100644 (file)
@@ -30,6 +30,7 @@ package jexer.tterminal;
 
 import java.awt.Graphics2D;
 import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.CharArrayWriter;
 import java.io.InputStream;
@@ -256,7 +257,7 @@ public class ECMA48 implements Runnable {
     /**
      * The type of emulator to be.
      */
-    private DeviceType type = DeviceType.VT102;
+    private final DeviceType type;
 
     /**
      * The scrollback buffer characters + attributes.
@@ -655,7 +656,8 @@ public class ECMA48 implements Runnable {
             this.inputStream  = new TimeoutInputStream(inputStream, 2000);
         }
         if (type == DeviceType.XTERM) {
-            this.input    = new InputStreamReader(this.inputStream, "UTF-8");
+            this.input    = new InputStreamReader(new BufferedInputStream(
+                this.inputStream, 1024 * 128), "UTF-8");
             this.output   = new OutputStreamWriter(new
                 BufferedOutputStream(outputStream), "UTF-8");
             this.outputStream = null;
@@ -760,11 +762,28 @@ public class ECMA48 implements Runnable {
                                 int ch = Character.codePointAt(readBufferUTF8,
                                     i);
                                 i += Character.charCount(ch);
-                                consume(ch);
+
+                                // Special case for VT10x: 7-bit characters
+                                // only.
+                                if ((type == DeviceType.VT100)
+                                    || (type == DeviceType.VT102)
+                                ) {
+                                    consume(ch & 0x7F);
+                                } else {
+                                    consume(ch);
+                                }
                             }
                         } else {
                             for (int i = 0; i < rc; i++) {
-                                consume(readBuffer[i]);
+                                // Special case for VT10x: 7-bit characters
+                                // only.
+                                if ((type == DeviceType.VT100)
+                                    || (type == DeviceType.VT102)
+                                ) {
+                                    consume(readBuffer[i] & 0x7F);
+                                } else {
+                                    consume(readBuffer[i]);
+                                }
                             }
                         }
                     }
@@ -4905,16 +4924,11 @@ public class ECMA48 implements Runnable {
      *
      * @param ch character from the remote side
      */
-    private void consume(int ch) {
+    private void consume(final int ch) {
 
         // DEBUG
         // System.err.printf("%c STATE = %s\n", ch, scanState);
 
-        // Special case for VT10x: 7-bit characters only
-        if ((type == DeviceType.VT100) || (type == DeviceType.VT102)) {
-            ch = (ch & 0x7F);
-        }
-
         // Special "anywhere" states
 
         // 18, 1A                     --> execute, then switch to SCAN_GROUND