From a52a890c0333e49a2b680e27e48b553217c0fc94 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 25 Apr 2020 09:18:55 +0000 Subject: [PATCH] Part of solution to performance problems ftn-setup.js and xtrn-setup.js where Display.prototype.__getUpdateList__ was taking > 1 second on an rPi3: We need to avoid using Frame.clear() which invalidates the entire frame and requires an update check of every cell (e.g. thousands in a typical frame). So we're going to depend on Frame.cleartoeol() which needed its own optimization to invalidate every cell of the current line even when the cells were already blank (undefined). So only mark the cells for update if they actually have data in them that is being cleared. Also, the putmsg() method was taking on a CRLF to the output string when word-wrap was enabled. So removing the trailing whitespace after word wrap does its thing. If this breaks other scripts, then perhaps we need to restore the original CRLF on the end of the word-wrapped string, but *only* if there was a CRLF on the end of the original string to begin with. --- exec/load/frame.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/exec/load/frame.js b/exec/load/frame.js index 7f58aeae76..8910027618 100644 --- a/exec/load/frame.js +++ b/exec/load/frame.js @@ -952,13 +952,13 @@ Frame.prototype.cleartoeol = function(attr) { return false; for(var x=px;x<this.__properties__.data[py].length;x++) { if(this.__properties__.data[py][x]) { - this.__properties__.data[py][x].ch = undefined; + if(this.__properties__.data[py][x].ch !== undefined) { + this.__properties__.data[py][x].ch = undefined; + this.__properties__.display.updateChar(this,x - this.__position__.offset.x, this.__position__.cursor.y); + } this.__properties__.data[py][x].attr = attr; } } - for(var x=this.__position__.cursor.x;x<this.width;x++) { - this.__properties__.display.updateChar(this,x,this.__position__.cursor.y); - } } Frame.prototype.crlf = function() { this.__position__.cursor.x = 0; @@ -991,7 +991,7 @@ Frame.prototype.putmsg = function(str,attr) { var remainingWidth = this.width - this.__position__.cursor.x; if(str.length > remainingWidth) { str = word_wrap(str,remainingWidth,str.length,false).split('\n'); - str = str.shift() + '\r\n' + word_wrap(str.join('\r\n'),this.width,remainingWidth,false); + str = str.shift() + '\r\n' + word_wrap(str.join('\r\n'),this.width,remainingWidth,false).trimRight(); } } str = str.toString().split(''); @@ -1565,6 +1565,7 @@ Display.prototype.__updateChar__ = function(x,y/*,data*/) { this.__properties__.update[y] = {}; this.__properties__.update[y][x] = 1; /*data; */ } + Display.prototype.__getUpdateList__ = function() { var list = []; for(var y in this.__properties__.update) { -- GitLab