[balsheet-pnl] faster definition of balance lists

because the accounts and accounts-cols-data have direct 1-to-1
mapping, it is not necessary to map accounts and retrieve from
accounts-cols-data. mapping from accounts-cols-data produces
identical results, avoiding O(N^2) access from accounts-cols-data.
This commit is contained in:
Christopher Lam 2022-04-11 09:36:52 +08:00
parent 736d223198
commit 1420368b5b

View File

@ -753,17 +753,17 @@ also show overall period profit & loss."))
;; account-balances is a list of monetary amounts ;; account-balances is a list of monetary amounts
(accounts-balances (accounts-balances
(map (map
(lambda (acc) (match-lambda
(cons acc (let ((cols-data (assoc-ref accounts-cols-data acc))) ((acc . cols-data)
(map col-datum-get-split-balance cols-data)))) (cons acc (map col-datum-get-split-balance cols-data))))
accounts)) accounts-cols-data))
(accounts-balances-with-closing (accounts-balances-with-closing
(map (map
(lambda (acc) (match-lambda
(cons acc (let ((cols-data (assoc-ref accounts-cols-data acc))) ((acc . cols-data)
(map col-datum-get-split-balance-with-closing cols-data)))) (cons acc (map col-datum-get-split-balance-with-closing cols-data))))
accounts)) accounts-cols-data))
(exchange-fn (and common-currency (exchange-fn (and common-currency
(gnc:case-exchange-time-fn (gnc:case-exchange-time-fn
@ -914,11 +914,10 @@ also show overall period profit & loss."))
;; split is the last one at date boundary ;; split is the last one at date boundary
(accounts-splits-dates (accounts-splits-dates
(map (map
(lambda (acc) (match-lambda
(cons acc (let ((cols-data (assoc-ref accounts-cols-data acc))) ((acc . cols-data)
(list->vector (cons acc (list->vector (map col-datum-get-last-split cols-data)))))
(map col-datum-get-last-split cols-data))))) accounts-cols-data))
accounts))
(get-cell-anchor-fn (get-cell-anchor-fn
(lambda (account col-idx) (lambda (account col-idx)
@ -944,10 +943,10 @@ also show overall period profit & loss."))
;; dates. split-value-balance determined by transaction currency. ;; dates. split-value-balance determined by transaction currency.
(accounts-value-balances (accounts-value-balances
(map (map
(lambda (acc) (match-lambda
(cons acc (let ((cols-data (assoc-ref accounts-cols-data acc))) ((acc . cols-data)
(map col-datum-get-split-value-balance cols-data)))) (cons acc (map col-datum-get-split-value-balance cols-data))))
accounts)) accounts-cols-data))
;; a vector of collectors whereby each collector is the sum ;; a vector of collectors whereby each collector is the sum
;; of asset and liability split-value-balances at report ;; of asset and liability split-value-balances at report