[report-utilities] more efficient gnc:accounts-get-commodities

don't create intermediate lists which are immediately used and
discarded.

don't locale-compare commodity names, which has locale-transform
overhead, and creates lots of temporary strings.

testing for duplicates via O(N) member is very adequate because
num(unique commodities) is expected to be small.

use the stack when accumulating commodities, avoiding need to prepend
and reverse.
pull/1850/head
Christopher Lam 2 years ago
parent 7a17b24e34
commit 1a5247c10e

@ -229,12 +229,7 @@
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
(all-splits (get-all-splits currency-accounts end-date))
(interesting-splits (sort (filter interesting-split? all-splits) date<?))
(commodity-list (sort-and-delete-duplicates
commodity-list
(lambda (a b)
(gnc:string-locale<? (gnc-commodity-get-unique-name a)
(gnc-commodity-get-unique-name b)))
gnc-commodity-equal))
(commodity-list (delete-duplicates commodity-list))
(work-to-do (length commodity-list)))
(map
(lambda (c work-done)

@ -217,14 +217,11 @@
;; Get the list of all different commodities that are used within the
;; 'accounts', excluding the 'exclude-commodity'.
(define (gnc:accounts-get-commodities accounts exclude-commodity)
(delete exclude-commodity
(sort-and-delete-duplicates
(map xaccAccountGetCommodity accounts)
(lambda (a b)
(gnc:string-locale<? (gnc-commodity-get-unique-name a)
(gnc-commodity-get-unique-name b)))
gnc-commodity-equiv)))
(if (null? accounts)
'()
(let ((comm (xaccAccountGetCommodity (car accounts)))
(accum (gnc:accounts-get-commodities (cdr accounts) exclude-commodity)))
(if (or (equal? exclude-commodity comm) (member comm accum)) accum (cons comm accum)))))
;; Returns the depth of the current account hierarchy, that is, the
;; maximum level of subaccounts in the tree

@ -739,12 +739,7 @@ also show overall period profit & loss."))
;; generate an exchange-fn for date, and cache its result.
(get-date-exchange-fn
(let ((h (make-hash-table))
(commodities (sort-and-delete-duplicates
(map xaccAccountGetCommodity accounts)
(lambda (a b)
(gnc:string-locale<? (gnc-commodity-get-unique-name a)
(gnc-commodity-get-unique-name b)))
gnc-commodity-equal)))
(commodities (gnc:accounts-get-commodities accounts #f)))
(lambda (date)
(or (hashv-ref h date)
(let ((exchangefn (gnc:case-exchange-time-fn

@ -331,7 +331,7 @@
'("#200.00" "$340.00" "30 FUNDS" "$14,424.52" "$106,709.00" "$106,709.00")
(sxml->table-row-col sxml 1 3 6))
(test-equal "show-rates enabled"
'("#1.00" "$1.7000" "1 FUNDS" "$480 + 85/104")
'("1 FUNDS" "$480 + 85/104" "#1.00" "$1.7000")
(sxml->table-row-col sxml 2 #f #f)))
;;make-multilevel

Loading…
Cancel
Save