From 7015bcedafc5a1622887bb84ece9c6c123893272 Mon Sep 17 00:00:00 2001 From: Billouboq Date: Mon, 13 Mar 2017 23:05:52 +0100 Subject: [PATCH] perf: improve ETag match loop closes #22 --- HISTORY.md | 1 + index.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e463052..f2dd739 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ unreleased ========== * Fix handling of modified headers with invalid dates + * perf: improve ETag match loop 0.5.0 / 2017-02-21 ================== diff --git a/index.js b/index.js index dd49dee..86b61c8 100644 --- a/index.js +++ b/index.js @@ -58,13 +58,18 @@ function fresh (reqHeaders, resHeaders) { // if-none-match if (noneMatch && noneMatch !== '*') { var etag = resHeaders['etag'] - var etagStale = !etag || noneMatch.split(TOKEN_LIST_REGEXP).every(function (match) { - return match !== etag && match !== 'W/' + etag && 'W/' + match !== etag - }) - if (etagStale) { + if (!etag) { return false } + + var matches = noneMatch.split(TOKEN_LIST_REGEXP) + for (var i = 0; i < matches.length; i++) { + var match = matches[i] + if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) { + return false + } + } } // if-modified-since