From 396f4fc78eb2684b360402287754711964525b5e Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 2 Dec 2016 12:15:54 -0500 Subject: [PATCH] avoid CPU-costly Date.toLocale(Date|Time)String() in logger page source: * https://github.com/gorhill/uBlock/commit/02a79ea9fcb8315cc525d8156349b9c79e512bac * https://github.com/gorhill/uBlock/commit/235d1266e8283c8afc27e9b20ad1657d5a92d995 * https://github.com/gorhill/uBlock/commit/3b41237e4b4f08903ea435d6df4762c9dda573ec --- src/js/logger-ui.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js index cc126f0..81378cb 100644 --- a/src/js/logger-ui.js +++ b/src/js/logger-ui.js @@ -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. @@ -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'); @@ -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'); @@ -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) {