]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
perf(makeDateFromInput): no need to match regex if input is a Date
authorPatrick Browne <patrick.browne@amadeus.com>
Wed, 11 Jun 2014 13:37:19 +0000 (15:37 +0200)
committerPatrick Browne <patrick.browne@amadeus.com>
Wed, 11 Jun 2014 13:43:21 +0000 (15:43 +0200)
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.

moment.js

index 07448344c8956853eee889e7fc3a6e7d9cfaa0e6..de222b140a25808263a0d683224028796595296f 100644 (file)
--- a/moment.js
+++ b/moment.js
     }
 
     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') {