From c31889b9d52f1cebb3b4d848dbb1ebd2229d38c0 Mon Sep 17 00:00:00 2001 From: Tim Tucker Date: Wed, 20 Mar 2013 09:55:58 -0300 Subject: [PATCH 1/2] Only get types once in mergeArrays Make a max of 2 calls to exports.getType instead of 4 calls. Should be slightly faster and a little smaller when minified. --- knockout.mapping.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/knockout.mapping.js b/knockout.mapping.js index 2ac4a3d..5cfff29 100644 --- a/knockout.mapping.js +++ b/knockout.mapping.js @@ -237,12 +237,14 @@ } function mergeArrays(a, b) { - if (exports.getType(a) !== "array") { - if (exports.getType(a) === "undefined") a = []; + var typeA = exports.getType(a); + if (typeA !== "array") { + if (typeA === "undefined") a = []; else a = [a]; } - if (exports.getType(b) !== "array") { - if (exports.getType(b) === "undefined") b = []; + var typeB = exports.getType(b); + if (typeB !== "array") { + if (typeB === "undefined") b = []; else b = [b]; } From 5dbea2b99610addcde5c1b252643556d1dfc689f Mon Sep 17 00:00:00 2001 From: Tim Tucker Date: Wed, 20 Mar 2013 14:18:08 -0300 Subject: [PATCH 2/2] Shorter method with direct compare to undefined --- knockout.mapping.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/knockout.mapping.js b/knockout.mapping.js index 5cfff29..1c1ffcb 100644 --- a/knockout.mapping.js +++ b/knockout.mapping.js @@ -237,15 +237,18 @@ } function mergeArrays(a, b) { - var typeA = exports.getType(a); - if (typeA !== "array") { - if (typeA === "undefined") a = []; - else a = [a]; + if (a === undefined) { + a = []; } - var typeB = exports.getType(b); - if (typeB !== "array") { - if (typeB === "undefined") b = []; - else b = [b]; + else if (exports.getType(a) !== "array") { + a = [a]; + } + + if (b === undefined) { + b = []; + } + else if (exports.getType(b) !== "array") { + b = [b]; } return ko.utils.arrayGetDistinctValues(a.concat(b));