From cb91995a204b2775252325d9c5f5ed0c28e5c6fd Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Fri, 25 Dec 2020 22:22:33 +0800 Subject: [PATCH 1/2] Revert "http: remove dead code from internal/http.js" This reverts commit 9156f430b5889623b5a8ebef9059ec7212a31b8a. --- lib/internal/http.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/internal/http.js b/lib/internal/http.js index 081f13c0b95e91..0065f93fd896f0 100644 --- a/lib/internal/http.js +++ b/lib/internal/http.js @@ -11,8 +11,14 @@ const { const { setUnrefTimeout } = require('internal/timers'); const { PerformanceEntry, notify } = internalBinding('performance'); +let nowCache; let utcCache; +function nowDate() { + if (!nowCache) cache(); + return nowCache; +} + function utcDate() { if (!utcCache) cache(); return utcCache; @@ -20,11 +26,13 @@ function utcDate() { function cache() { const d = new Date(); - utcCache = d.toUTCString(); - setUnrefTimeout(resetCache, 1000 - d.getMilliseconds()); + nowCache = DatePrototypeValueOf(d); + utcCache = DatePrototypeToUTCString(d); + setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d)); } function resetCache() { + nowCache = undefined; utcCache = undefined; } @@ -47,6 +55,7 @@ function emitStatistics(statistics) { module.exports = { kOutHeaders: Symbol('kOutHeaders'), kNeedDrain: Symbol('kNeedDrain'), + nowDate, utcDate, emitStatistics }; From bae71f095530d6d2dd81a3906d7985c47c1e36ea Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Fri, 25 Dec 2020 22:22:33 +0800 Subject: [PATCH 2/2] http: remove dead code from internal/http.js PR-URL: https://github.com/nodejs/node/pull/36630 Refs: https://github.com/nodejs/node/pull/32329 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- lib/internal/http.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/internal/http.js b/lib/internal/http.js index 0065f93fd896f0..b17687d4d81624 100644 --- a/lib/internal/http.js +++ b/lib/internal/http.js @@ -5,20 +5,13 @@ const { Date, DatePrototypeGetMilliseconds, DatePrototypeToUTCString, - DatePrototypeValueOf, } = primordials; const { setUnrefTimeout } = require('internal/timers'); const { PerformanceEntry, notify } = internalBinding('performance'); -let nowCache; let utcCache; -function nowDate() { - if (!nowCache) cache(); - return nowCache; -} - function utcDate() { if (!utcCache) cache(); return utcCache; @@ -26,13 +19,11 @@ function utcDate() { function cache() { const d = new Date(); - nowCache = DatePrototypeValueOf(d); utcCache = DatePrototypeToUTCString(d); setUnrefTimeout(resetCache, 1000 - DatePrototypeGetMilliseconds(d)); } function resetCache() { - nowCache = undefined; utcCache = undefined; } @@ -55,7 +46,6 @@ function emitStatistics(statistics) { module.exports = { kOutHeaders: Symbol('kOutHeaders'), kNeedDrain: Symbol('kNeedDrain'), - nowDate, utcDate, emitStatistics };