pouchdb/pouchdb — pull request #3138 by nolanlawson (2014-12-08 06:36:49+00:00)
Title: (#2543) - avoid excessive sort() in merge.js

So this is an old bug, but we've finally got around to fixing it.

Some kind of `sort()` is required, otherwise the `npm run test-unit` fails.

However, I found a more efficient method of sorting by just trusting that the array is already sorted and then using a binary search insertion.

Note as well that I'm using a custom comparator, so instead of comparing two arrays, I'm comparing the first elements in each arrays, which it was doing anyway but now I'm being explicit about it.

The added test is funny because it actually times out (>100 s) before this commit, but after this commit it finishes in a reasonable amount of time (< 5 seconds in all adapters).