From 2aa2f77881a75b7706121ab7723d4a2c8965c1ed Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Tue, 22 Nov 2016 00:49:18 +0700 Subject: [PATCH] Fix #186 unnecessary `if` statement inside `while` loop --- src/ua-parser.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/ua-parser.js b/src/ua-parser.js index 8d5d513..2056ae8 100644 --- a/src/ua-parser.js +++ b/src/ua-parser.js @@ -83,33 +83,26 @@ rgx : function () { - var result, i = 0, j, k, p, q, matches, match, args = arguments; + var result = {}, i = 0, j, k, p, q, matches, match, args = arguments; + + // construct object barebones + for (p = 0; p < args[1].length; p++) { + q = args[1][p]; + result[typeof q === OBJ_TYPE ? q[0] : q] = undefined; + } // loop through all regexes maps while (i < args.length && !matches) { var regex = args[i], // even sequence (0,2,4,..) props = args[i + 1]; // odd sequence (1,3,5,..) - - // construct object barebones - if (typeof result === UNDEF_TYPE) { - result = {}; - for (p in props) { - if (props.hasOwnProperty(p)){ - q = props[p]; - if (typeof q === OBJ_TYPE) { - result[q[0]] = undefined; - } else { - result[q] = undefined; - } - } - } - } + j = k = 0; // try matching uastring with regexes - j = k = 0; while (j < regex.length && !matches) { + matches = regex[j++].exec(this.getUA()); + if (!!matches) { for (p = 0; p < props.length; p++) { match = matches[++k];