From ffd51b54f79e7de61ae9eef276ca5a3af0594d67 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 9 Jul 2009 15:09:40 +0000 Subject: Go faster * Remove checkBounds from vt320 which masks bugs * Inline markLine since we have no JIT to forklift it git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@362 df292f66-193f-0410-a5fc-6d59da041ff2 --- src/de/mud/terminal/VDUBuffer.java | 70 +++++++++++++-------------------- src/de/mud/terminal/vt320.java | 79 ++++++++++++++++++++------------------ 2 files changed, 69 insertions(+), 80 deletions(-) (limited to 'src/de/mud/terminal') diff --git a/src/de/mud/terminal/VDUBuffer.java b/src/de/mud/terminal/VDUBuffer.java index f9940c3..1b90da9 100644 --- a/src/de/mud/terminal/VDUBuffer.java +++ b/src/de/mud/terminal/VDUBuffer.java @@ -142,11 +142,10 @@ public class VDUBuffer { */ public void putChar(int c, int l, char ch, int attributes) { - c = checkBounds(c, 0, width - 1); - l = checkBounds(l, 0, height - 1); charArray[screenBase + l][c] = ch; charAttributes[screenBase + l][c] = attributes; - markLine(l, 1); + if (l < height) + update[l + 1] = true; } /** @@ -156,8 +155,6 @@ public class VDUBuffer { * @see #putChar */ public char getChar(int c, int l) { - c = checkBounds(c, 0, width - 1); - l = checkBounds(l, 0, height - 1); return charArray[screenBase + l][c]; } @@ -168,8 +165,6 @@ public class VDUBuffer { * @see #putChar */ public int getAttributes(int c, int l) { - c = checkBounds(c, 0, width - 1); - l = checkBounds(l, 0, height - 1); return charAttributes[screenBase + l][c]; } @@ -192,8 +187,6 @@ public class VDUBuffer { * @see #redraw */ public void insertChar(int c, int l, char ch, int attributes) { - c = checkBounds(c, 0, width - 1); - l = checkBounds(l, 0, height - 1); System.arraycopy(charArray[screenBase + l], c, charArray[screenBase + l], c + 1, width - c - 1); System.arraycopy(charAttributes[screenBase + l], c, @@ -212,8 +205,6 @@ public class VDUBuffer { * @see #redraw */ public void deleteChar(int c, int l) { - c = checkBounds(c, 0, width - 1); - l = checkBounds(l, 0, height - 1); if (c < width - 1) { System.arraycopy(charArray[screenBase + l], c + 1, charArray[screenBase + l], c, width - c - 1); @@ -320,8 +311,6 @@ public class VDUBuffer { * @see #redraw */ public synchronized void insertLine(int l, int n, boolean scrollDown) { - l = checkBounds(l, 0, height - 1); - char cbuf[][] = null; int abuf[][] = null; int offset = 0; @@ -485,8 +474,6 @@ public class VDUBuffer { * @see #deleteLine */ public void deleteLine(int l) { - l = checkBounds(l, 0, height - 1); - int bottom = (l > bottomMargin ? height - 1: (l < topMargin?topMargin:bottomMargin + 1)); int numRows = bottom - l - 1; @@ -523,9 +510,6 @@ public class VDUBuffer { * @see #redraw */ public void deleteArea(int c, int l, int w, int h, int curAttr) { - c = checkBounds(c, 0, width - 1); - l = checkBounds(l, 0, height - 1); - int endColumn = c + w; int targetRow = screenBase + l; for (int i = 0; i < h && l + i < height; i++) { @@ -556,8 +540,6 @@ public class VDUBuffer { * @param doshow */ public void showCursor(boolean doshow) { - if (doshow != showcursor) - markLine(cursorY, 1); showcursor = doshow; } @@ -566,18 +548,18 @@ public class VDUBuffer { * @return visibility */ public boolean isCursorVisible() { - return showcursor; + return showcursor; } - + /** * Puts the cursor at the specified position. * @param c column * @param l line */ public void setCursorPosition(int c, int l) { - cursorX = checkBounds(c, 0, width - 1); - cursorY = checkBounds(l, 0, height - 1); - markLine(cursorY, 1); + cursorX = c; + cursorY = l; + update[cursorY + 1] = true; } /** @@ -623,18 +605,18 @@ public class VDUBuffer { * @param l2 line that is the bottom */ public void setMargins(int l1, int l2) { - if (l1 > l2) - return; - - if (l1 < 0) - l1 = 0; - if (l2 > height - 1) - l2 = height - 1; - - topMargin = l1; - bottomMargin = l2; - } - + if (l1 > l2) + return; + + if (l1 < 0) + l1 = 0; + if (l2 > height - 1) + l2 = height - 1; + + topMargin = l1; + bottomMargin = l2; + } + /** * Set the top scroll margin for the screen. If the current bottom margin * is smaller it will become the top margin and the line will become the @@ -813,16 +795,18 @@ public class VDUBuffer { * @see #redraw */ public void markLine(int l, int n) { - l = checkBounds(l, 0, height - 1); for (int i = 0; (i < n) && (l + i < height); i++) update[l + i + 1] = true; } - private int checkBounds(int value, int lower, int upper) { - if (value < lower) return lower; - if (value > upper) return upper; - return value; - } +// private static int checkBounds(int value, int lower, int upper) { +// if (value < lower) +// return lower; +// else if (value > upper) +// return upper; +// else +// return value; +// } /** a generic display that should redraw on demand */ protected VDUDisplay display; diff --git a/src/de/mud/terminal/vt320.java b/src/de/mud/terminal/vt320.java index 4df3717..417ff3b 100644 --- a/src/de/mud/terminal/vt320.java +++ b/src/de/mud/terminal/vt320.java @@ -134,8 +134,8 @@ public abstract class vt320 extends VDUBuffer implements VDUInput { @Override public void setScreenSize(int c, int r, boolean broadcast) { - int oldrows = getRows(); - //int oldcols = getColumns(); + int oldrows = height; + //int oldcols = width; if (debug>2) { debugStr.append("setscreensize (") @@ -153,7 +153,12 @@ public void setScreenSize(int c, int r, boolean broadcast) { /* Tricky, since the VDUBuffer works strangely. */ if (r > oldrows) { - setCursorPosition(C, R + (r-oldrows)); + int newR = R + (r - oldrows); + if (newR < 0) + newR = 0; + else if (newR > height - 1) + newR = height - 1; + setCursorPosition(C, R = newR); redraw(); } if (broadcast) { @@ -1484,11 +1489,11 @@ public void setScreenSize(int c, int r, boolean broadcast) { } private void _SetCursor(int row, int col) { - int maxr = getRows(); + int maxr = height - 1; int tm = getTopMargin(); - R = (row < 0)?0:row; - C = (col < 0)?0:col; + R = (row < 0)?0: row; + C = (col < 0)?0: (col > width - 1) ? width - 1 : col; if (!moveoutsidemargins) { R += tm; @@ -1498,32 +1503,32 @@ public void setScreenSize(int c, int r, boolean broadcast) { } private void putChar(char c, boolean doshowcursor) { - int rows = getRows(); //statusline - int columns = getColumns(); + int rows = this.height; //statusline + int columns = this.width; // byte msg[]; - if (debug > 4) { - debugStr.append("putChar(") - .append(c) - .append(" [") - .append((int) c) - .append("]) at R=") - .append(R) - .append(" , C=") - .append(C) - .append(", columns=") - .append(columns) - .append(", rows=") - .append(rows); - debug(debugStr.toString()); - debugStr.setLength(0); - } - //markLine(R, 1); - if (c > 255) { - if (debug > 0) - debug("char > 255:" + (int) c); - //return; - } +// if (debug > 4) { +// debugStr.append("putChar(") +// .append(c) +// .append(" [") +// .append((int) c) +// .append("]) at R=") +// .append(R) +// .append(" , C=") +// .append(C) +// .append(", columns=") +// .append(columns) +// .append(", rows=") +// .append(rows); +// debug(debugStr.toString()); +// debugStr.setLength(0); +// } +// markLine(R, 1); +// if (c > 255) { +// if (debug > 0) +// debug("char > 255:" + (int) c); +// //return; +// } switch (term_state) { @@ -2084,7 +2089,7 @@ public void setScreenSize(int c, int r, boolean broadcast) { for (int i = 0; i <= DCEvar; i++) { switch (DCEvars[i]) { case 3: /* 80 columns*/ - setScreenSize(80, getRows(), true); + setScreenSize(80, height, true); break; case 4: /* scrolling mode, smooth */ break; @@ -2126,7 +2131,7 @@ public void setScreenSize(int c, int r, boolean broadcast) { vt52mode = false; break; case 3: /* 132 columns*/ - setScreenSize(132, getRows(), true); + setScreenSize(132, height, true); break; case 6: /* DECOM: move inside margins. */ moveoutsidemargins = false; @@ -2193,7 +2198,7 @@ public void setScreenSize(int c, int r, boolean broadcast) { vt52mode = true; break; case 3: /* 80 columns*/ - setScreenSize(80, getRows(), true); + setScreenSize(80, height, true); break; case 6: /* DECOM: move outside margins. */ moveoutsidemargins = true; @@ -2413,7 +2418,7 @@ public void setScreenSize(int c, int r, boolean broadcast) { /* used for tabsets */ switch (DCEvars[0]) { case 3:/* clear them */ - Tabs = new byte[getColumns()]; + Tabs = new byte[width]; break; case 0: Tabs[C] = 0; @@ -2943,15 +2948,15 @@ public void setScreenSize(int c, int r, boolean broadcast) { onegl = -1; // Single shift override /* reset tabs */ - int nw = getColumns(); + int nw = width; if (nw < 132) nw = 132; Tabs = new byte[nw]; for (int i = 0; i < nw; i += 8) { Tabs[i] = 1; } - deleteArea(0, 0, getColumns(), getRows(), attributes); - setMargins(0, getRows()); + deleteArea(0, 0, width, height, attributes); + setMargins(0, height); C = R = 0; _SetCursor(0, 0); -- cgit v1.2.3