Skip to content

Commit 77d148b

Browse files
committed
Eval: evalSelect: optimize extract
Further optimization seems possible, but would require more equilibristics.
1 parent d5a65d2 commit 77d148b

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/Nix/Eval.hs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,25 +407,28 @@ evalSelect aset attr =
407407
s <- aset
408408
path <- traverse evalGetterKeyName attr
409409

410-
extract s path
410+
extract path s
411411

412412
where
413-
extract :: v -> NonEmpty VarName -> m (Either (v, NonEmpty VarName) (m v))
414-
extract x path@(k :| ks) =
413+
extract :: NonEmpty VarName -> v -> m (Either (v, NonEmpty VarName) (m v))
414+
extract path@(k :| ks) x =
415415
do
416416
x' <- fromValueMay x
417417

418-
case x' of
419-
Nothing -> pure $ Left (x, path)
420-
Just (s :: AttrSet v, p :: PositionSet)
421-
| Just t <- M.lookup k s ->
422-
do
423-
list
424-
(pure . pure)
425-
(\ (y : ys) -> ((`extract` (y :| ys)) =<<))
426-
ks
427-
$ demand t
428-
| otherwise -> Left . (, path) <$> toValue (s, p)
418+
maybe
419+
(pure $ Left (x, path))
420+
(\ (s :: AttrSet v, _ :: PositionSet) ->
421+
maybe
422+
(pure $ Left (x, path))
423+
(list
424+
(pure . pure)
425+
(\ (y : ys) -> ((extract (y :| ys)) =<<))
426+
ks
427+
. demand
428+
)
429+
((`M.lookup` s) k)
430+
)
431+
x'
429432

430433
-- | Evaluate a component of an attribute path in a context where we are
431434
-- *retrieving* a value

0 commit comments

Comments
 (0)