Skip to content

Commit

Permalink
Improve the performance of display refresh.
Browse files Browse the repository at this point in the history
Just setting textContent on a <td> actually implicitly removes the
existing text node and appends a new one; Instead, just mutate the
existing text node.

This is especially painful on Chrome with the "Edit with emacs"
extension, which has a hook that runs whenever the DOM is modified.
  • Loading branch information
nelhage committed Jun 4, 2011
1 parent fc20993 commit fa7b174
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions betaweb.js
Expand Up @@ -80,7 +80,7 @@ function initBeta() {
cells = rows[i].cells;
for (j = 0; j < cells.length; j++) {
if (cells[j].nodeName == 'TD')
BETA.regCells.push(cells[j]);
BETA.regCells.push(cells[j].firstChild);
}
}

Expand Down Expand Up @@ -129,7 +129,7 @@ function resetBeta(rom) {
var th = document.createElement('th');
var td = document.createElement('td');
th.textContent = toHex(i) + ":";
td.textContent = '';
td.appendChild(document.createTextNode())
tr.appendChild(th);
tr.appendChild(td);
BETA.memTab.appendChild(tr);
Expand Down Expand Up @@ -168,7 +168,7 @@ function refreshDisplay() {
for (i = 0; i < 31; i++)
BETA.regCells[i].textContent = toHex(CPU.regs[i]);
for (i = 0; i < MMU.memory.length; i++)
BETA.memTab.rows[i].cells[1].textContent = toHex(MMU.memory[i]);
BETA.memTab.rows[i].cells[1].firstChild.textContent = toHex(MMU.memory[i]);
}

function initTerm() {
Expand Down

0 comments on commit fa7b174

Please sign in to comment.