Skip to content

Commit

Permalink
Skip intermediate list when decoding App
Browse files Browse the repository at this point in the history
This seems to speed up decoding of Prelude and cpkg caches
by 1-2%.

Context: #1804.
  • Loading branch information
sjakobi committed May 24, 2020
1 parent d339948 commit 56d1797
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions dhall/src/Dhall/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Dhall.Syntax
, Var(..)
)

import Data.Foldable (toList, foldl')
import Data.Foldable (toList)
import Data.Monoid ((<>))
import Data.Text (Text)
import Data.Void (Void, absurd)
Expand Down Expand Up @@ -234,15 +234,19 @@ decodeExpressionInternal decodeEmbed = go

case tag of
0 -> do
f <- go
!f <- go

xs <- replicateDecoder (len - 2) go
let loop n !acc
| n <= 0 = return acc
| otherwise = do
!x <- go
loop (n - 1) (App acc x)

if null xs
then die "Non-standard encoding of a function with no arguments"
else return ()
let nArgs = len - 2

return (foldl' App f xs)
if nArgs <= 0
then die "Non-standard encoding of a function with no arguments"
else loop nArgs f

1 -> do
case len of
Expand Down

0 comments on commit 56d1797

Please sign in to comment.