gexp: Reduce allocations in 'gexp-attribute'.

* guix/gexp.scm (gexp-attribute): Use 'fold' and 'fold/tree' instead of
'append-map'.
This commit is contained in:
Ludovic Courtès 2021-02-23 14:19:48 +01:00
parent c8bd5fa59c
commit fcde4e10b8
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -757,19 +757,28 @@ attribute that is traversed."
(append (let ((attribute (self-attribute gexp))) (append (let ((attribute (self-attribute gexp)))
(validate gexp attribute) (validate gexp attribute)
attribute) attribute)
(append-map (match-lambda (reverse
(($ <gexp-input> (? gexp? exp)) (fold (lambda (input result)
(gexp-attribute exp self-attribute (match input
#:validate validate)) (($ <gexp-input> (? gexp? exp))
(($ <gexp-input> (lst ...)) (append (gexp-attribute exp self-attribute
(append-map (lambda (item) #:validate validate)
(gexp-attribute item self-attribute result))
#:validate (($ <gexp-input> (lst ...))
validate)) (fold/tree (lambda (obj result)
lst)) (match obj
(_ ((? gexp? exp)
'())) (append (gexp-attribute exp self-attribute
(gexp-references gexp))) #:validate validate)
result))
(_
result)))
result
lst))
(_
result)))
'()
(gexp-references gexp))))
equal?) equal?)
'())) ;plain Scheme data type '())) ;plain Scheme data type