Slight improvement to getLocation

This commit is contained in:
Andrzej Rybczak 2022-03-09 16:51:23 +01:00
parent 3890b0a600
commit ce7112a309

View File

@ -525,11 +525,11 @@ getLocation ix (Env fork size ref _) = do
-- specific effects for reinterpretation. -- specific effects for reinterpretation.
case fork of case fork of
NoFork -> pure $ Location i es NoFork -> pure $ Location i es
Forks _ baseIx lref forks -> do Forks _ baseIx lref forks
| i >= baseIx -> do
EnvRef _ les _ <- readIORef lref EnvRef _ les _ <- readIORef lref
if i >= baseIx pure $ Location (i - baseIx) les
then pure $ Location (i - baseIx) les | otherwise -> go es# i forks
else go es# i forks
where where
go :: SmallMutableArray# RealWorld Any go :: SmallMutableArray# RealWorld Any
-> Int -> Int
@ -537,8 +537,8 @@ getLocation ix (Env fork size ref _) = do
-> IO Location -> IO Location
go es# i = \case go es# i = \case
NoFork -> pure $ Location i (SmallMutableArray es#) NoFork -> pure $ Location i (SmallMutableArray es#)
Forks _ baseIx lref forks -> do Forks _ baseIx lref forks
| i >= baseIx -> do
EnvRef _ les _ <- readIORef lref EnvRef _ les _ <- readIORef lref
if i >= baseIx pure $ Location (i - baseIx) les
then pure $ Location (i - baseIx) les | otherwise -> go es# i forks
else go es# i forks