1
1
mirror of https://github.com/github/semantic.git synced 2024-11-23 16:37:50 +03:00

Avoid refetching the bounds.

This commit is contained in:
Rob Rix 2017-06-21 13:17:44 -04:00
parent e532f7d2fb
commit c2daf3af07

View File

@ -25,6 +25,7 @@ ses eq as' bs'
| null as = That <$> toList bs
| otherwise = reverse (searchUpToD 0 (Array.array (1, 1) [(1, Endpoint 0 (-1) [])]))
where (as, bs) = (Array.listArray (0, pred n) (toList as'), Array.listArray (0, pred m) (toList bs'))
(aBounds, bBounds) = (Array.bounds as, Array.bounds bs)
(n, m) = (length as', length bs')
-- Search an edit graph for the shortest edit script up to a given proposed edit distance, building on the results of previous searches.
@ -45,14 +46,14 @@ ses eq as' bs'
up = v ! succ k
-- | Move downward from a given vertex, inserting the element for the corresponding row.
moveDownFrom (Endpoint x y script) = Endpoint x (succ y) (if inRange (Array.bounds bs) y then That (bs ! y) : script else script)
moveDownFrom (Endpoint x y script) = Endpoint x (succ y) (if inRange bBounds y then That (bs ! y) : script else script)
-- | Move rightward from a given vertex, deleting the element for the corresponding column.
moveRightFrom (Endpoint x y script) = Endpoint (succ x) y (if inRange (Array.bounds as) x then This (as ! x) : script else script)
moveRightFrom (Endpoint x y script) = Endpoint (succ x) y (if inRange aBounds x then This (as ! x) : script else script)
-- | Slide down any diagonal edges from a given vertex.
slideFrom (Endpoint x y script)
| inRange (Array.bounds as) x, a <- as ! x
, inRange (Array.bounds bs) y, b <- bs ! y
| inRange aBounds x, a <- as ! x
, inRange bBounds y, b <- bs ! y
, a `eq` b = slideFrom (Endpoint (succ x) (succ y) (These a b : script))
| otherwise = Endpoint x y script