From b79aeabc4dd7e803c1e985c316e23381d09dc3b3 Mon Sep 17 00:00:00 2001 From: YoonSoo_Shin <89785501+MCprotein@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:53:12 +0900 Subject: [PATCH] lib: avoid for of loop and remove unnecessary variable in zlib removed the unnecessary declaration of 'i' in the _final method scope and changed the for of loop to a for loop Refs: https://github.com/nodejs/node/blob/main/doc/contributing/primordials.md#unsafe-array-iteration PR-URL: https://github.com/nodejs/node/pull/54258 Reviewed-By: Daeyeon Jeong Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat --- lib/zlib.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 509f83731e9116..1a00ea59b484a6 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -361,11 +361,10 @@ ZlibBase.prototype._final = function(callback) { // Z_NO_FLUSH (< Z_TREES) < Z_BLOCK < Z_PARTIAL_FLUSH < // Z_SYNC_FLUSH < Z_FULL_FLUSH < Z_FINISH const flushiness = []; -let i = 0; const kFlushFlagList = [Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH]; -for (const flushFlag of kFlushFlagList) { - flushiness[flushFlag] = i++; +for (let i = 0; i < kFlushFlagList.length; i++) { + flushiness[kFlushFlagList[i]] = i; } function maxFlush(a, b) {