From fcde4e10b87db9a71dbc115af548aeabe9068310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Tue, 23 Feb 2021 14:19:48 +0100 Subject: gexp: Reduce allocations in 'gexp-attribute'. * guix/gexp.scm (gexp-attribute): Use 'fold' and 'fold/tree' instead of 'append-map'. --- guix/gexp.scm | 35 ++++++++++++++++++++++------------- 1 file 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? exp)) - (gexp-attribute exp self-attribute - #:validate validate)) - (($ (lst ...)) - (append-map (lambda (item) - (gexp-attribute item self-attribute - #:validate - validate)) - lst)) - (_ - '())) - (gexp-references gexp))) + (reverse + (fold (lambda (input result) + (match input + (($ (? gexp? exp)) + (append (gexp-attribute exp self-attribute + #:validate validate) + result)) + (($ (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 -- cgit v1.2.3