From: Patrick Browne Date: Wed, 11 Jun 2014 13:37:19 +0000 (+0200) Subject: perf(makeDateFromInput): no need to match regex if input is a Date X-Git-Tag: 2.8.0~26^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e28ed19d66e2206dc234131497c2a82587b09e45;p=thirdparty%2Fmoment.git perf(makeDateFromInput): no need to match regex if input is a Date The moment constructor when passed a Date should be the fastest. There is no need to match the aspNetJsonRegex before testing if the `input` is a Date. --- diff --git a/moment.js b/moment.js index 07448344c..de222b140 100644 --- a/moment.js +++ b/moment.js @@ -1487,20 +1487,24 @@ } function makeDateFromInput(config) { - var input = config._i, - matched = aspNetJsonRegex.exec(input); - + var input = config._i; if (input === undefined) { config._d = new Date(); - } else if (matched) { + return; + } else if (isDate(input)) { + config._d = new Date(+input); + return; + } + + var matched = aspNetJsonRegex.exec(input); + + if (matched) { config._d = new Date(+matched[1]); } else if (typeof input === 'string') { makeDateFromString(config); } else if (isArray(input)) { config._a = input.slice(0); dateFromConfig(config); - } else if (isDate(input)) { - config._d = new Date(+input); } else if (typeof(input) === 'object') { dateFromObject(config); } else if (typeof(input) === 'number') {