mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-14 19:05:10 -05:00
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:
parent
c8bd5fa59c
commit
fcde4e10b8
1 changed files with 22 additions and 13 deletions
|
@ -757,19 +757,28 @@ (define* (gexp-attribute gexp self-attribute #:optional (equal? equal?)
|
|||
(append (let ((attribute (self-attribute gexp)))
|
||||
(validate gexp attribute)
|
||||
attribute)
|
||||
(append-map (match-lambda
|
||||
(($ <gexp-input> (? gexp? exp))
|
||||
(gexp-attribute exp self-attribute
|
||||
#:validate validate))
|
||||
(($ <gexp-input> (lst ...))
|
||||
(append-map (lambda (item)
|
||||
(gexp-attribute item self-attribute
|
||||
#:validate
|
||||
validate))
|
||||
lst))
|
||||
(_
|
||||
'()))
|
||||
(gexp-references gexp)))
|
||||
(reverse
|
||||
(fold (lambda (input result)
|
||||
(match input
|
||||
(($ <gexp-input> (? gexp? exp))
|
||||
(append (gexp-attribute exp self-attribute
|
||||
#:validate validate)
|
||||
result))
|
||||
(($ <gexp-input> (lst ...))
|
||||
(fold/tree (lambda (obj result)
|
||||
(match obj
|
||||
((? gexp? exp)
|
||||
(append (gexp-attribute exp self-attribute
|
||||
#:validate validate)
|
||||
result))
|
||||
(_
|
||||
result)))
|
||||
result
|
||||
lst))
|
||||
(_
|
||||
result)))
|
||||
'()
|
||||
(gexp-references gexp))))
|
||||
equal?)
|
||||
'())) ;plain Scheme data type
|
||||
|
||||
|
|
Loading…
Reference in a new issue