Thomas Rast [off-list ref] writes:
At the very least it should be possible to change in_merge_bases() to
not do any of the post-filtering; perhaps like the patch below.
I do not recall the details but the post-filtering was added after
the initial naive version without it that was posted to the list did
not work correctly in corner cases. I wouldn't doubt that N*(N-1)
loop can be optimized to something with log(N), but I offhand find
it hard to believe "to not do any" could be correct without seeing
more detailed analysis.