Skip to content

Commit c43bfd2

Browse files
authored
Skip generating the intermediate list when decoding App (#1809)
This seems to speed up decoding of Prelude and cpkg caches by 1-2%. Context: #1804.
1 parent d339948 commit c43bfd2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

dhall/src/Dhall/Binary.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import Dhall.Syntax
5050
, Var(..)
5151
)
5252

53-
import Data.Foldable (toList, foldl')
53+
import Data.Foldable (toList)
5454
import Data.Monoid ((<>))
5555
import Data.Text (Text)
5656
import Data.Void (Void, absurd)
@@ -234,15 +234,19 @@ decodeExpressionInternal decodeEmbed = go
234234

235235
case tag of
236236
0 -> do
237-
f <- go
237+
!f <- go
238238

239-
xs <- replicateDecoder (len - 2) go
239+
let loop n !acc
240+
| n <= 0 = return acc
241+
| otherwise = do
242+
!x <- go
243+
loop (n - 1) (App acc x)
240244

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

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

247251
1 -> do
248252
case len of

0 commit comments

Comments
 (0)