mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-21 15:28:15 +03:00
optimize compareSuffix a bit
This commit is contained in:
parent
ed0a850a56
commit
fd99ecb1e1
@ -122,13 +122,13 @@ data Position
|
|||||||
--
|
--
|
||||||
-- /O(n)/, where /n/ is the number of name segments.
|
-- /O(n)/, where /n/ is the number of name segments.
|
||||||
compareSuffix :: Name -> Name -> Ordering
|
compareSuffix :: Name -> Name -> Ordering
|
||||||
compareSuffix (Name _ ss0) (Name _ ss1) =
|
compareSuffix (Name _ ss0) =
|
||||||
go (toList ss0) (toList ss1)
|
foldr f (const EQ) ss0 . List.NonEmpty.toList . reverseSegments
|
||||||
where
|
where
|
||||||
go :: Ord a => [a] -> [a] -> Ordering
|
f :: NameSegment -> ([NameSegment] -> Ordering) -> ([NameSegment] -> Ordering)
|
||||||
go [] _ = EQ -- only compare up to entire suffix (first arg)
|
f x acc = \case
|
||||||
go _ [] = LT
|
[] -> LT
|
||||||
go (x : xs) (y : ys) = compare y x <> go xs ys
|
y : ys -> compare y x <> acc ys
|
||||||
|
|
||||||
-- | Cons a name segment onto the head of a relative name. Monotonic with respect to ordering: it is safe to use
|
-- | Cons a name segment onto the head of a relative name. Monotonic with respect to ordering: it is safe to use
|
||||||
-- @cons s@ as the first argument to @Map.mapKeysMonotonic@.
|
-- @cons s@ as the first argument to @Map.mapKeysMonotonic@.
|
||||||
|
Loading…
Reference in New Issue
Block a user