1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00

Short-circuit single-element lists.

This commit is contained in:
Rob Rix 2017-10-23 23:23:08 -04:00
parent e0ca6c7ec4
commit 7c193c0b5e

View File

@ -83,6 +83,8 @@ findNearestNeighbourTo :: (Foldable syntax, Functor syntax, GAlign syntax)
findNearestNeighbourTo canCompare as bs = go as bs
where go as [] = This . (termIndex &&& term) <$> as
go [] bs = That . (termIndex &&& term) <$> bs
go [a] [b] | canCompareTerms canCompare (term a) (term b) = [These (termIndex a, term a) (termIndex b, term b)]
| otherwise = [That (termIndex b, term b), This (termIndex a, term a)]
go unmappedA@(UnmappedTerm minA _ _ : _) (termB@(UnmappedTerm j _ b) : restUnmappedB) =
fromMaybe (That (j, b) : go unmappedA restUnmappedB) $ do
-- Look up the nearest unmapped term in `unmappedA`.