hterm: terminal: speed up realize helpers slightly
Sometimes these functions get called with the same sizes as the
terminal is already using. To avoid needless reprocessing, add
some checks to return early when the state is already in sync.
Change-Id: I81ea7bfc1cbc3892b9b238cd7694356c6090e9e7
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/1657573
Reviewed-by: Vitaliy Shipitsyn <vsh@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index d3decb7..c2d6505 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -1065,14 +1065,22 @@
* @param {number} rowCount The number of rows.
*/
hterm.Terminal.prototype.realizeSize_ = function(columnCount, rowCount) {
- if (columnCount != this.screenSize.width)
- this.realizeWidth_(columnCount);
+ let notify = false;
- if (rowCount != this.screenSize.height)
+ if (columnCount != this.screenSize.width) {
+ notify = true;
+ this.realizeWidth_(columnCount);
+ }
+
+ if (rowCount != this.screenSize.height) {
+ notify = true;
this.realizeHeight_(rowCount);
+ }
// Send new terminal size to plugin.
- this.io.onTerminalResize_(columnCount, rowCount);
+ if (notify) {
+ this.io.onTerminalResize_(columnCount, rowCount);
+ }
};
/**
@@ -1093,6 +1101,10 @@
throw new Error('Attempt to realize bad width: ' + columnCount);
var deltaColumns = columnCount - this.screen_.getWidth();
+ if (deltaColumns == 0) {
+ // No change, so don't bother recalculating things.
+ return;
+ }
this.screenSize.width = columnCount;
this.screen_.setColumnCount(columnCount);
@@ -1130,6 +1142,10 @@
throw new Error('Attempt to realize bad height: ' + rowCount);
var deltaRows = rowCount - this.screen_.getHeight();
+ if (deltaRows == 0) {
+ // No change, so don't bother recalculating things.
+ return;
+ }
this.screenSize.height = rowCount;