* Pretty big optimization with TextView: Don't attempt to draw empty items - which needs SGR work and all sorts of processing - if there is not (yet) a non-empty string to draw

This commit is contained in:
Bryan Ashby 2016-08-06 20:11:04 -06:00
parent 6283a047f3
commit 2b68201f7d
1 changed files with 26 additions and 15 deletions

View File

@ -24,8 +24,6 @@ function TextView(options) {
View.call(this, options); View.call(this, options);
var self = this;
if(options.maxLength) { if(options.maxLength) {
this.maxLength = options.maxLength; this.maxLength = options.maxLength;
} else { } else {
@ -36,6 +34,7 @@ function TextView(options) {
this.justify = options.justify || 'right'; this.justify = options.justify || 'right';
this.resizable = miscUtil.valueWithDefault(options.resizable, true); this.resizable = miscUtil.valueWithDefault(options.resizable, true);
this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true); this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true);
this.text = options.text || '';
if(_.isString(options.textOverflow)) { if(_.isString(options.textOverflow)) {
this.textOverflow = options.textOverflow; this.textOverflow = options.textOverflow;
@ -87,6 +86,7 @@ function TextView(options) {
), false); ), false);
}; };
*/ */
this.drawText = function(s) { this.drawText = function(s) {
// //
@ -109,7 +109,6 @@ function TextView(options) {
textToDraw = renderSubstr(textToDraw, renderLength - this.dimens.width, renderLength); textToDraw = renderSubstr(textToDraw, renderLength - this.dimens.width, renderLength);
} }
} else { } else {
if(renderLength > this.dimens.width) {
if(this.textOverflow && if(this.textOverflow &&
this.dimens.width > this.textOverflow.length && this.dimens.width > this.textOverflow.length &&
renderLength - this.textOverflow.length >= this.textOverflow.length) renderLength - this.textOverflow.length >= this.textOverflow.length)
@ -120,7 +119,6 @@ function TextView(options) {
} }
} }
} }
}
this.client.term.write(padStr( this.client.term.write(padStr(
textToDraw, textToDraw,
@ -132,18 +130,31 @@ function TextView(options) {
), false); ), false);
}; };
this.getEndOfTextColumn = function() { this.getEndOfTextColumn = function() {
var offset = Math.min(this.text.length, this.dimens.width); var offset = Math.min(this.text.length, this.dimens.width);
return this.position.col + offset; return this.position.col + offset;
}; };
// :TODO: Whatever needs init here should be done separately from setText() since it redraws/etc. // :TODO: Whatever needs init here should be done separately from setText() since it redraws/etc.
this.setText(options.text || ''); // this.setText(options.text || '');
} }
util.inherits(TextView, View); util.inherits(TextView, View);
TextView.prototype.redraw = function() { TextView.prototype.redraw = function() {
//
// A lot of views will get an initial redraw() with empty text (''). We can short
// circuit this by NOT doing any of the work if this is the initial drawText
// and there is no actual text (e.g. save SGR's and processing)
//
if(!this.hasDrawnOnce) {
if(!this.text) {
return;
}
}
this.hasDrawnOnce = true;
TextView.super_.prototype.redraw.call(this); TextView.super_.prototype.redraw.call(this);
if(_.isString(this.text)) { if(_.isString(this.text)) {