From cdafdf3a414f3143e03affd64d1513f08f3596cd Mon Sep 17 00:00:00 2001 From: Weijia Wang <381152119@qq.com> Date: Thu, 7 Dec 2017 21:34:53 +0800 Subject: [PATCH] http: simplify `isInvalidPath` The loop unrolling shows no performance benefits in V8 6.3. This change is to simplify `isInvalidPath` without performance regression. --- lib/_http_client.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 5b568628006d68..70b0488f43dbfb 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -51,20 +51,7 @@ const errors = require('internal/errors'); // This function is used in the case of small paths, where manual character code // checks can greatly outperform the equivalent regexp (tested in V8 5.4). function isInvalidPath(s) { - var i = 0; - if (s.charCodeAt(0) <= 32) return true; - if (++i >= s.length) return false; - if (s.charCodeAt(1) <= 32) return true; - if (++i >= s.length) return false; - if (s.charCodeAt(2) <= 32) return true; - if (++i >= s.length) return false; - if (s.charCodeAt(3) <= 32) return true; - if (++i >= s.length) return false; - if (s.charCodeAt(4) <= 32) return true; - if (++i >= s.length) return false; - if (s.charCodeAt(5) <= 32) return true; - ++i; - for (; i < s.length; ++i) + for (var i = 0; i < s.length; ++i) if (s.charCodeAt(i) <= 32) return true; return false; }