summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2021-02-23 14:19:48 +0100
committerLudovic Courtès <ludo@gnu.org>2021-02-23 15:24:49 +0100
commitfcde4e10b87db9a71dbc115af548aeabe9068310 (patch)
treea9679f84ea23469f7cc6b5880e9d5e5214cac999
parentc8bd5fa59c4493734fa41f6c4d5b972ba8b5b141 (diff)
gexp: Reduce allocations in 'gexp-attribute'.
* guix/gexp.scm (gexp-attribute): Use 'fold' and 'fold/tree' instead of 'append-map'.
-rw-r--r--guix/gexp.scm35
1 files changed, 22 insertions, 13 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm
index cad57f62ca..8cd44ba534 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -757,19 +757,28 @@ attribute that is traversed."
(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