From: Isaac Cambron Date: Mon, 21 Jul 2014 05:22:34 +0000 (-0400) Subject: moar speed X-Git-Tag: 2.8.0~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24fbb01fff8fbdf149fd6a6c6e616a40ebedf86d;p=thirdparty%2Fmoment.git moar speed --- diff --git a/.gitignore b/.gitignore index 5794af789..5a540d3cf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ min/tests.js sauce_connect.log .sauce-labs.creds npm-debug.log -benchmarks/results.csv diff --git a/Gruntfile.js b/Gruntfile.js index 7b49a3827..943e74948 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -188,10 +188,9 @@ module.exports = function (grunt) { targetLocales: embedLocaleSrc }, benchmark: { - all: { - src: ['benchmarks/*.js'], - dest: 'benchmarks/results.json', - } + all: { + src: ['benchmarks/*.js'] + } } }); diff --git a/benchmarks/results.json b/benchmarks/results.json deleted file mode 100644 index b3f7aaf8b..000000000 --- a/benchmarks/results.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "name": "clone", - "timestamp": "Sun Jul 20 2014 23:14:34 GMT-0400 (EDT)", - "count": 1925, - "cycles": 3, - "hz": 34836.98543958899 - }, - { - "name": "clone", - "timestamp": "Sun Jul 20 2014 23:21:33 GMT-0400 (EDT)", - "count": 1885, - "cycles": 8, - "hz": 36659.44586569106 - }, - { - "name": "clone", - "timestamp": "Mon Jul 21 2014 00:50:03 GMT-0400 (EDT)", - "count": 11378, - "cycles": 4, - "hz": 210942.42334154248 - } -] \ No newline at end of file diff --git a/moment.js b/moment.js index 4afc67b06..1278b511f 100644 --- a/moment.js +++ b/moment.js @@ -28,19 +28,8 @@ // internal storage for locale config files locales = {}, - // moment internal properties - momentProperties = [ - '_isAMomentObject', - '_i', - '_f', - '_l', - '_strict', - '_tzm', - '_isUTC', - '_offset', - '_pf', - '_locale' - ]; + // extra moment internal properties (plugins register props here) + momentProperties = [], // check for nodeJS hasModule = (typeof module !== 'undefined' && module.exports), @@ -377,10 +366,11 @@ // Moment prototype object function Moment(config, skipOverflow) { - if (skipOverflow != false) { - checkOverflow(config); + if (skipOverflow !== false) { + checkOverflow(config); } copyConfig(this, config); + this._d = new Date(+config._d); } // Duration Constructor @@ -445,15 +435,46 @@ function copyConfig(to, from) { var i, prop, val; - for (i in momentProperties) { - prop = momentProperties[i]; - val = from[prop]; - if (typeof val !== 'undefined') { - to[prop] = val; - } + if (typeof from._isAMomentObject !== 'undefined') { + to._isAMomentObject = from._isAMomentObject; + } + if (typeof from._i !== 'undefined') { + to._i = from._i; + } + if (typeof from._f !== 'undefined') { + to._f = from._f; + } + if (typeof from._l !== 'undefined') { + to._l = from._l; + } + if (typeof from._strict !== 'undefined') { + to._strict = from._strict; + } + if (typeof from._tzm !== 'undefined') { + to._tzm = from._tzm; + } + if (typeof from._isUTC !== 'undefined') { + to._isUTC = from._isUTC; + } + if (typeof from._offset !== 'undefined') { + to._offset = from._offset; + } + if (typeof from._pf !== 'undefined') { + to._pf = from._pf; + } + if (typeof from._locale !== 'undefined') { + to._locale = from._locale; } - to._d = new Date(+from._d); + if (momentProperties.length > 0) { + for (i in momentProperties) { + prop = momentProperties[i]; + val = from[prop]; + if (typeof val !== 'undefined') { + to[prop] = val; + } + } + } return to; } @@ -1466,7 +1487,7 @@ for (i = 0; i < config._f.length; i++) { currentScore = 0; - tempConfig = extend({}, config); + tempConfig = copyConfig({}, config); tempConfig._pf = defaultParsingFlags(); tempConfig._f = config._f[i]; makeDateFromStringAndFormat(tempConfig); @@ -1694,7 +1715,6 @@ if (moment.isMoment(input)) { return new Moment(input, true); - } else if (format) { if (isArray(format)) { makeDateFromStringAndArray(config);