gnucash maint: [trep-engine] faster csv list processing
Christopher Lam
clam at code.gnucash.org
Mon Feb 28 08:44:55 EST 2022
Updated via https://github.com/Gnucash/gnucash/commit/c3883e70 (commit)
from https://github.com/Gnucash/gnucash/commit/c6429804 (commit)
commit c3883e703b177e5ef015347bf86450952423b468
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Feb 28 09:23:24 2022 +0800
[trep-engine] faster csv list processing
instead of scanning the row 5 times: (length, make-list, append, map,
string-join), walk the list once building the accumulator along the way.
diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm
index 4e4cccdaf..ec21d6d78 100644
--- a/gnucash/report/trep-engine.scm
+++ b/gnucash/report/trep-engine.scm
@@ -470,18 +470,28 @@ in the Options panel."))
str)
(display #\" port))))
- (define max-items (apply max (map length lst)))
+ (define max-items
+ (let lp ((lst lst) (maximum 0))
+ (cond
+ ((null? lst) maximum)
+ ((pair? lst) (lp (cdr lst) (max maximum (length (car lst)))))
+ (else (error "strify " lst " must be a proper list")))))
(define (strify obj)
(cond
- ((not obj) "")
+ ((or (null? obj) (not obj)) "")
((string? obj) (string-sanitize-csv obj))
((number? obj) (number->string (exact->inexact obj)))
- ((list? obj) (string-join
- (map strify
- (append obj
- (make-list (- max-items (length obj)) #f)))
- ","))
+ ((pair? obj) (let lp ((row obj) (acc '()) (pad max-items))
+ (cond
+ ((zero? pad) (string-concatenate-reverse acc))
+ ((null? row) (lp '() (cons "," acc) (1- pad)))
+ ((pair? row) (lp (cdr row)
+ (cons* (if (pair? (cdr row)) "," "")
+ (strify (car row))
+ acc)
+ (1- pad)))
+ (else (error "strify " obj " must be a proper list")))))
((gnc:gnc-monetary? obj) (strify (gnc:gnc-monetary-amount obj)))
(else (object->string obj))))
Summary of changes:
gnucash/report/trep-engine.scm | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
More information about the gnucash-changes
mailing list