Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
avoid CPU-costly Date.toLocale(Date|Time)String() in logger page
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill authored and xofe committed Nov 24, 2017
1 parent e793c17 commit b71f16b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/js/logger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ var prettyRequestTypes = {
'xmlhttprequest': 'xhr'
};

var timeOptions = {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
};

var dateOptions = {
month: 'short',
day: '2-digit'
};

/******************************************************************************/

// Adjust top padding of content table, to match that of toolbar height.
Expand Down Expand Up @@ -220,6 +208,12 @@ var createHiddenTextNode = function(text) {

/******************************************************************************/

var padTo2 = function(v) {
return v < 10 ? '0' + v : v;
};

/******************************************************************************/

var createGap = function(tabId, url) {
var tr = createRow('1');
tr.classList.add('doc');
Expand Down Expand Up @@ -276,9 +270,11 @@ var renderLogEntry = function(entry) {
}

// Fields common to all rows.
var time = new Date(entry.tstamp);
tr.cells[0].textContent = time.toLocaleTimeString('fullwide', timeOptions);
tr.cells[0].title = time.toLocaleDateString('fullwide', dateOptions);
var time = logDate;
time.setTime(entry.tstamp - logDateTimezoneOffset);
tr.cells[0].textContent = padTo2(time.getUTCHours()) + ':' +
padTo2(time.getUTCMinutes()) + ':' +
padTo2(time.getSeconds());

if ( entry.tab ) {
tr.classList.add('tab');
Expand All @@ -296,6 +292,10 @@ var renderLogEntry = function(entry) {
tbody.insertBefore(tr, tbody.firstChild);
};

// Reuse date objects.
var logDate = new Date(),
logDateTimezoneOffset = logDate.getTimezoneOffset() * 60000;

/******************************************************************************/

var renderLogEntries = function(response) {
Expand Down

0 comments on commit b71f16b

Please sign in to comment.