Chromium Code Reviews| Index: Source/devtools/front_end/utilities.js |
| diff --git a/Source/devtools/front_end/utilities.js b/Source/devtools/front_end/utilities.js |
| index e6c3c3e215305efa972f8dd4268c3a4ea3b04d61..57ba4fc64f57fbfe41c2f6e7ed547aea4d704e4b 100644 |
| --- a/Source/devtools/front_end/utilities.js |
| +++ b/Source/devtools/front_end/utilities.js |
| @@ -717,29 +717,18 @@ function mergeOrIntersect(array1, array2, comparator, mergeNotIntersect) |
| var result = []; |
| var i = 0; |
| var j = 0; |
| - while (i < array1.length || j < array2.length) { |
| - if (i === array1.length) { |
| - result = result.concat(array2.slice(j)); |
| - j = array2.length; |
| - } else if (j === array2.length) { |
| - result = result.concat(array1.slice(i)); |
| - i = array1.length; |
| - } else { |
| - var compareValue = comparator(array1[i], array2[j]) |
| - if (compareValue < 0) { |
| - if (mergeNotIntersect) |
| - result.push(array1[i]); |
| - ++i; |
| - } else if (compareValue > 0) { |
| - if (mergeNotIntersect) |
| - result.push(array2[j]); |
| - ++j; |
| - } else { |
| - result.push(array1[i]); |
| - ++i; |
| - ++j; |
| - } |
| - } |
| + while (i < array1.length && j < array2.length) { |
| + var compareValue = comparator(array1[i], array2[j]); |
| + if (mergeNotIntersect || !compareValue) |
| + result.push(compareValue <= 0 ? array1[i] : array2[j]); |
| + if (compareValue <= 0) |
| + i++; |
| + if (compareValue >= 0) |
| + j++; |
| + } |
| + if (mergeNotIntersect) { |
| + result = result.concat(array1.slice(i)); |
|
pfeldman
2014/02/14 16:02:17
Isn't this expensive? Both concat and slice are cr
alph
2014/02/14 16:31:37
Indeed. Fixed.
|
| + result = result.concat(array2.slice(j)); |
| } |
| return result; |
| } |