diff --git a/platform/features/table/src/controllers/MCTTableController.js b/platform/features/table/src/controllers/MCTTableController.js index 45c3be85ee..52d1c2f7f4 100644 --- a/platform/features/table/src/controllers/MCTTableController.js +++ b/platform/features/table/src/controllers/MCTTableController.js @@ -436,9 +436,25 @@ define( * @param {Object} searchElement Object to find the insertion point for */ MCTTableController.prototype.findInsertionPoint = function (searchArray, searchElement) { - //First, use a binary search to find the correct insertion point - var index = this.binarySearch(searchArray, searchElement, 0, searchArray.length - 1); - var testIndex = index; + var index; + var textIndex; + var first = searchArray[0]; + var last = searchArray[searchArray.length - 1]; + + // Shortcut check for append/prepend + if (first && this.sortComparator(first, searchElement) <= 0) { + index = testIndex = 0; + } else if (last && this.sortComparator(last, searchElement) >= 0) { + index = testIndex = searchArray.length - 1; + } else { + // use a binary search to find the correct insertion point + index = testIndex = this.binarySearch( + searchArray, + searchElement, + 0, + searchArray.length - 1 + ); + } //It's possible that the insertion point is a duplicate of the element to be inserted var isDupe = function () {