From 754f834035271279b279a13514c8031069dc4f76 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 4 Dec 2018 23:09:40 -0400 Subject: Optimize - don't do attributes.slice() as often If it makes sense to reuse an attributes array, do that. --- util/ansi.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'util') diff --git a/util/ansi.js b/util/ansi.js index 94de1a3..04722c0 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -134,7 +134,7 @@ const ansi = { let showCursor = true let cursorRow = 1 let cursorCol = 1 - const attributes = [] + let attributes = [] for (let charI = 0; charI < text.length; charI++) { const cursorIndex = (cursorRow - 1) * scrCols + (cursorCol - 1) @@ -219,13 +219,14 @@ const ansi = { if (text[charI] === 'm') { const removeAttribute = attr => { if (attributes.includes(attr)) { + attributes = attributes.slice() attributes.splice(attributes.indexOf(attr), 1) } } for (const arg of args) { if (arg === '0') { - attributes.splice(0, attributes.length) + attributes = [] } else if (arg === '22') { // Neither bold nor faint removeAttribute('1') removeAttribute('2') @@ -251,7 +252,7 @@ const ansi = { removeAttribute('4' + i) } } else { - attributes.push(arg) + attributes = attributes.concat([arg]) } } } @@ -260,8 +261,7 @@ const ansi = { } chars[cursorIndex] = { - char: text[charI], - attributes: attributes.slice() + char: text[charI], attributes } cursorCol++ @@ -289,8 +289,6 @@ const ansi = { differences.push(newChars.slice()) } else { const charsEqual = (oldChar, newChar) => { - // TODO: Check attributes. - if (oldChar.char !== newChar.char) { return false } -- cgit 1.3.0-6-gf8a5